Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
ObjectSpace.allocation_generation
(untyped) -> (::Integer | nil)
allocation_generation(object) → integer or nil
ext/objspace/object_tracing.c
View on GitHub ↗
static VALUE
allocation_generation(VALUE self, VALUE obj)
{
struct allocation_info *info = lookup_allocation_info(obj);
if (info) {
return SIZET2NUM(info->generation);
}
else {
return Qnil;
}
}
Returns garbage collector generation for the given object.
Example
class B include ObjectSpace def foo trace_object_allocations do obj = Object.new p "Generation is #{allocation_generation(obj)}" end end end B.new.foo #=> "Generation is 3"
See ::trace_object_allocations for more information and examples.
See also
.allocation_class_path
.allocation_method_id
.allocation_sourcefile
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0