From: Daniel Schierbeck Date: 2005-11-25T22:47:27+09:00 Subject: Re: `finalize' method? Jim Weirich wrote: > 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 > In that case I'd expect $global_reference to be nil after the `finalize' method is done executing, since the Klass instance has already been deemed ready for destruction. Cheers, Daniel