> Apart from what Guy wrote already, why do you need to determine the point in > time when finalizers are called? The whole idea of GC and finalization is > that you *don't* care when it happens. If you need to ensure (hint, hint) Yes. This was partly an academic question, partly because I feel in my guts that java people pretending that "it's not a problem we don't have multiple inheritance because you don't need it" and "it's not a problem we don't have destructors because you don't need it" are plain wrong (I do know this is making implementation easier so I'd like that people admit that) (and I am a bit sorry that ruby, otherwise a great language, follows this path), and partly because I've bumped into a similar problem in a java program I work on for a living (the need to free DB connections associated with out of scope java objects). In other words, in my opinion there are cases where IO can be freed with a try|begin/catch|rescue/finally|ensure but other cases where for example an object is a wrapper around some IO, and in such circumstances it makes good sense to free this IO when the object it out of scope instead of explicitely calling a close/free method, especially when there can be several locations of your program that make use of such an object. With a reference counting implementation of a GC (Perl, Python) the use of destructors for such a matter is immediate (and that may explain why they provide destructors, btw) but with a mark & sweep or another "asynchronous" GC it becomes a problem; this problem can possibly be workarounded by explicitely calling the GC from carefully crafter locations ("when a new request enters" comes to mind when you deal with server-based service), however I admit this is far from ideal. But even that seems impossible with ruby (and java) according to the results of my short program. > And another remark: as opposed to Java finalizers, Ruby finalizers are > guaranteed to be invoked, even on program exit: > > $ ruby -e 'ObjectSpace.define_finalizer(Object.new){ puts "called" }' > called > $ ruby -e 'o=Object.new;ObjectSpace.define_finalizer(o){ puts "called" }' > called Yes, and this is a very good point, I know that. Thanks for your message. -- Guillaume Cottenceau - http://zarb.org/~gc/