Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

ObjectSpace#dump_all

(?since: ::Integer | nil, ?full: ::boolish, ?output: ::Symbol) -> (::String | ::File | nil)
dump_all(output: :file, full: false, since: nil, shapes: true)

Dump the contents of the ruby heap as JSON.

output argument is the same as for dump.

full must be a boolean. If true, all heap slots are dumped including the empty ones (T_NONE).

since must be a non-negative integer or nil.

If since is a positive integer, only objects of that generation and newer generations are dumped. The current generation can be accessed using GC::count. Objects that were allocated without object allocation tracing enabled are ignored. See ::trace_object_allocations for more information and examples.

If since is omitted or is nil, all objects are dumped.

shapes must be a boolean or a non-negative integer.

If shapes is a positive integer, only shapes newer than the provided shape id are dumped. The current shape_id can be accessed using RubyVM.stat(:next_shape_id).

If shapes is false, no shapes are dumped.

To only dump objects allocated past a certain point you can combine since and shapes:

Example
ObjectSpace.trace_object_allocations_start
GC.start
gc_generation = GC.count
shape_generation = RubyVM.stat(:next_shape_id)
call_method_to_instrument
ObjectSpace.dump_all(since: gc_generation, shapes: shape_generation)

This method is only expected to work with C Ruby. This is an experimental method and is subject to change. In particular, the function signature and output format are not guaranteed to be compatible in future versions of ruby.

Ruby version changes

  1. 3.2