From: Robert Klemme Date: 2007-02-21T00:50:06+09:00 Subject: Re: Deconstructor to close file On 20.02.2007 14:12, Austin Ziegler wrote: > On 2/20/07, Robert Klemme wrote: >> On 20.02.2007 01:00, Austin Ziegler wrote: >> > There is no meaningful concept of a destructor in Ruby. There are >> > finalizers, but they're not guaranteed to be called. >> Are you sure about that? I know the statement to be true for Java but >> in which situation (other than an interpreter crash) is a finalizer not >> invoked? > > I recall reading a few things over the last couple of years. On > program termination, I think they will be called, Yes. Actually I found a regular way to prevent invocation: robert@fussel ~ $ ruby -e 'o=Object.new;ObjectSpace.define_finalizer(o) {p 222};exit 1' 222 robert@fussel ~ $ ruby -e 'o=Object.new;ObjectSpace.define_finalizer(o) {p 222};exit! 1' robert@fussel ~ $ So there is at least /one/ other way besides a process crash. I didn't think of exit! before. Good that we double checked. :-) > but things could > happen to keep an object around a lot longer than you think -- which > means that it's not something to trust. Yeah, don't trust the timing. And I definitively agree that there are often better means than finalizers. Kind regards robert