From: MikkelFJ Date: 2003-05-20T11:49:55+09:00 Subject: Re: An Object Going Out Of Scope "Brian Candler" wrote in message news:20030519161809.GA2900@uk.tiscali.com... > On Tue, May 20, 2003 at 12:55:22AM +0900, MikkelFJ wrote: > > I didn't go through all you examples, but I did say that you could still > > have references at time of finalization. > > But then what is the purpose of a "finalizer"? > > It's possible for an object to be assigned to a variable which goes out of > scope lots of times! The fact that you can close a file handle many times does not lead the conclusion that files should not be closed. I'm interested in ensuring cleanup after the scope of interest terminates, not the scope or lifetime of a variable or object as this can be arbitrarily complex. Just because we have GC we don't have to give up on stack semantics. > Would you really want to call a finalizer 6 times on the same object in the > above example? I don't think so. I would write my code in a sensible way. Making things easier does not liberate you from the necessity of reflecting about what you are doing. You seem to be assuming any object should be automatically finalized every time a reference goes out scope. This is not the point. Apart from that, you sometimes do want to call a cleanup method many times. Reference counted resources and semphores comes to mind. critsec.enter, critsec.exit. I recall a thread where some posters did have a problem with controlling file life time where I proposed a simple refcounted solution. > I think you are proposing that the variable itself can be tagged in a > special way, "do X when this variable goes out of scope". But you can > achieve this using 'ensure' already, without having to get the interpreter > involved: True, except it is more the auto declaration that goes out of scope, not necessarily the variable. I realized the ensure equivalance myself. See other post. With the auto syntax, you could programmatically do some more advanced cleanup logic which ensure would only make possible using preprocessed defines. Maurico was hinting at some almost possible implementation. In any case, ensure is a great feature that solves the essential problem. > > > { auto(:$critsec, :exit); @critsec.enter; .... } > > That doesn't make any sense to me - a global variable can never go out of > scope? No, but the auto declaration does. It's just like ensure at the end. I think you do follow me according to what you wrote earlier Mikkel