From: Michael Neumann Date: 2004-10-25T17:58:41+09:00 Subject: Re: Forcing a GC run On Mon, Oct 25, 2004 at 10:39:47AM +0900, Bill Atkins wrote: > How exactly did that happen? I'm confused. :) A finalizer was not invoked at life-time... ah, hard to explain, see yourself: def take_snapshot snap = [] ObjectSpace.define_finalizer(snap, proc { p "finalizer called" }) return snap end # BE CAREFUL! Might freeze your computer! loop do p "snap" take_snapshot end Memory consumption will grow towards infinity. Why? Probably because the proc, as it's a closure, implicitly references the snap object, and as such, snap will never be recycled. Whereas the following works fine: $fin = proc { p "finalizer called" } def take_snapshot snap = [] ObjectSpace.define_finalizer(snap, $fin) return snap end loop do p "snap" take_snapshot end Regards, Michael