From: Joel VanderWerf Date: 2007-05-23T10:57:13+09:00 Subject: Re: Confusing array garbage collection, how to get valid heap snapshot? Greg Fodor wrote: > We are working on tracking down a memory leak, and are hoping to use > heap snapshotting to find the culprit. Using the neat bleak_house > library: > > http://blog.evanweaver.com/articles/2007/04/28/bleak_house > > I have got snapshotting working on my local machine. Note this library > does not go through ObjectSpaces, but uses a custom ruby build, so its > much more accurate in showing the true state of the heap. However, > there seems to be a bit of a problem, this simple script I wrote for > testing purposes: > > # Snapshot here > a = Array.new(1000) { Object.new } > a = nil > 1.upto(20) { GC.start; ObjectSpace.garbage_collect; sleep 1; } > # Snapshot here This is probably not very helpful, because I don't know what bleak_house is but: - calling GC repeatedly is unlikely to make a difference - GC is conservative in treating stack data as potential pointers - you can see the effect in the following example: GC.start n0 = ObjectSpace.each_object(Object){} def foo a = Array.new(1000) { Object.new } a = nil a = Array.new(1000) { Object.new } a = nil a = Array.new(1000) { Object.new } a = nil end foo GC.start n1 = ObjectSpace.each_object(Object){} p n1 - n0 __END__ This outputs 998 for me. If you only create one array inside of #foo, the output is the same, probably since the stack space was reused. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407