From: Pit Capitain Date: 2005-04-13T15:42:50+09:00 Subject: Re: ability to run finalizers at a given point of a program? Robert Klemme schrieb: > > "Glenn Parker" schrieb im Newsbeitrag > news:425C50C4.4070504@comcast.net... > >> Do you know when the last "extraction" has been done (making it safe >> for your finalizer to run)? Can you use that knowledge to explicitly >> run the finalization method, instead of waiting for the GC? > > That's the exact right question. Because if one can invoke GC manually, > then one can as well invoke some cleanup method. Nothing really gained. In some unit tests it would be nice if you could force the GC to run the finalizers. For testing the finalizer code itself you just can call it explicitly, that's right. But how can you verify that after calling a cleanup method there are no more references to certain objects? The only way I could think of was explicitly starting the GC and checking whether the finalizers had been called. Unfortunately, this didn't work, because I couldn't reliably force the GC to run the finalizers. For example, on my system, Guy's code isn't working either: C:\tmp>ruby -v r.rb ruby 1.8.1 (2003-12-25) [i386-mswin32] *** constructor Foo was out-scoped. Gc was run. *** pseudo-destructor If this has changed in 1.8.2 I'd be glad to update, but I doubt it. Regards, Pit