From: Christian Neukirchen Date: 2005-11-26T01:28:58+09:00 Subject: Re: `finalize' method? Jim Weirich writes: > dasch wrote: >> Yeah, it's me again, your friendly neighbourhood power-suggester! >> >> I'm wondering why there isn't a `finalize' method classes can define, >> that will be called immediately before instances of that class are >> garbage collected? I'm aware of ObjectSpace.define_finalizer, but it >> seems un-OO, and it doesn't seem to work when being called from within >> the instance methods. It also seems as if the Proc sent to >> `define_finalizer' isn't called until *after* the object has been >> destroyed. > > That's correct, it prevents problems like the following code: > > class Klass > def finalize > $global_reference = self > end > end What's the problem if this method ran on the first GC once and then the object just stayed around? I.e. have a three-pass GC, mark, run, sweep? -- Christian Neukirchen http://chneukirchen.org