Explanation on Ruby ObjectSpace object allocation trace?

976 Views Asked by At

I'm trying to debug memory leak in a Rails App, and I'm trying to get a dump of existing objects, by using ObjectSpace#trace_object_allocations.

In order for me to better understand the output, I think I should fully understand the meaning of an output JSON line:

{
   "address":"0x7fb716009c20",
   "type":"STRING",
   "class":"0x7fb7360d40e0",
   "embedded":true,
   "bytesize":1,
   "value":"f",
   "encoding":"UTF-8",
   "file":"/Users/songyy/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/quoting.rb",
   "line":78,
   "method":"unquoted_false",
   "generation":93,
   "memsize":40,
   "flags":{
      "wb_protected":true,
      "old":true,
      "uncollectible":true,
      "marked":true
   }
}

Is there any reference, to which explains the exact meaning of the items in this JSON object?

Particularly, I'm interested in the meaning of:

  • class
  • embedded
  • bytesize
  • generation
  • flags
    • wb_protected
    • old
    • uncollectible
    • marked
1

There are 1 best solutions below

0
On

class: basically obj.class.object_id

embedded: true if string/array fits in a RVALUE (40 bytes on x64)

bytesize: odd that it is 1, would expect it to be all the extra bytes required on top of RVALUE

generation: GC "generation" that the object was allocated at. Smaller the number the older the object is.

wb_protected: write barrier protected, means object can not move to the old generation heap if it is in the young heap

marked: GC marked the object

Recommend you read through the source to expand on any of this. Very little documentation out ther.