In ruby 1.9.3, I'm using ObjectSpace to inspect the memory issue. The ObjectSpace.count_objects returns a hash, which looks like:
{:TOTAL=>1004232, :FREE=>258543, :T_OBJECT=>12519, :T_CLASS=>10318, :T_MODULE=>1330,
:T_FLOAT=>2024, :T_STRING=>555422, :T_REGEXP=>3543, :T_ARRAY=>68372, :T_HASH=>5399,
:T_STRUCT=>542, :T_BIGNUM=>8105, :T_FILE=>10, :T_DATA=>44277, :T_MATCH=>6, :T_COMPLEX=>1,
:T_RATIONAL=>82, :T_NODE=>31973, :T_ICLASS=>1766}
What does each hash value mean? And especially, why does the :TOTAL stay unchanged for a long time? Does it mean no new object is created?
I saw a similar posting, but no good answer yet.
Looking at the
T_CLASS
object we can see that these are counts. When I remove the class and start the Garbage Collector it reduces the count again.The TOTAL value remaining unchanged can not mean that there were no objects created, as obviously when you create a new object such as MyClass that count did not change. It could mean that it only reevaluates the total occasionally, not in real time.
But, with a little bit of math, when I sum the values, and remove the TOTAL count, I get TOTAL. So it looks like it is a count of the number of objects, which makes sense, when
count_objects
reports on the count of objects.