Actions
Bug #16788
closedT_CLASS counts classes double
Description
Consider the following code:
h = {}
ObjectSpace.count_objects(h)
puts "Counts: #{ h[:T_CLASS] }, #{ h[:T_ICLASS] }"
objects = []
classes = []
ObjectSpace.each_object(Object){|x| objects << x}
ObjectSpace.each_object(Class){|x| classes << x}
class Test
end
objects2 = []
classes2 = []
ObjectSpace.each_object(Object){|x| objects2 << x}
ObjectSpace.each_object(Class){|x| classes2 << x}
objects_ids = objects.map(&:object_id)
new_objects = objects2.reject { |e| objects_ids.include? e.object_id }
puts "New objects belongs to the classes: #{ new_objects.map(&:class).uniq }"
puts "New classes: #{classes2 - classes}"
h = {}
ObjectSpace.count_objects(h)
puts "Counts: #{ h[:T_CLASS] }, #{ h[:T_ICLASS] }"
The result is the following:
Counts: 690, 46
New objects belongs to the classes: [Array, Class]
New classes: [Test]
Counts: 692, 46
This means that the number of T_CLASS
is increased by 2 with the creation of 1 class. Why is this the case? Is this a bug?
Consider the slightly modified code with:
class Test
def self.foo
end
end
In this case the Singleton class is also created and the results are:
Counts: 690, 46
New objects belongs to the classes: [Array, Class]
New classes: [#<Class:Test>, Test]
Counts: 693, 46
In this case, T_CLASS
is increased by 3. So it seems like the issue is only with normal classes and not singleton ones.
Actions
Like0
Like0Like0Like0Like0Like0Like0