Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
ObjectSpace.count_tdata_objects
static VALUE
count_tdata_objects(int argc, VALUE *argv, VALUE self)
{
VALUE hash = setup_hash(argc, argv);
each_object_with_flags(cto_i, (void *)hash);
return hash;
}
Returns a hash containing the number of objects for each T_DATA type. The keys are Class objects when the T_DATA object has an associated class, or Symbol objects of the name defined in the rb_data_type_struct for internal T_DATA objects.
ObjectSpace.count_tdata_objects # => {RBS::Location => 39255, marshal_compat_table: 1, Encoding => 103, mutex: 1, ... }
If the optional argument result_hash is given, it is overwritten and returned. This is intended to avoid the probe effect.
This method is intended for developers interested in performance and memory usage of Ruby programs. The contents of the returned hash is implementation specific and may change in the future.
This method is only expected to work with C Ruby.