From: "Avdi B. Grimm" Date: 2001-10-24T09:03:44+09:00 Subject: [ruby-talk:23125] Re: Bruce Eckel's opinion of Ruby On Tue, 2001-10-23 at 19:27, Michael Neumann wrote: > Avdi B. Grimm wrote: > > > Using this there is no need for destructors. > > > > I have to disagree with this statement. There *are* cases where the > > block paradigm is simply not appropriate, and destructors are. > > Sometimes it's possible to kludge in a solution using the block > > paradigm; but it's not pretty. It's not a terribly rare occurance to > > have objects which (a) /must/ release resources before being > > garbage-collected, and (b) have non-determinate lifetimes. > > True. You cannot do everything with blocks. > In Ruby you have class ObjectSpace that lets you define finalizer > methods. This is not very nice, but it works. I would go so far as to say it doesn't work at all, unless I completely failed to understand it. Once the ObjectSpace-defined constructor kicks in, the object is *already gone*. All the destructor gets is (IIRC) the ID of the object. I haven't yet figured out how this can be used to free resources that only the now-deceased object posessed the keys to. Perhaps one has to maintain some sort of global ID/Resource map, and the destructor has to look up the resources to free via the ID...? Pardon me but, yeeeecchhhhh! That's just horrid. ~Avdi