[Prev][Next][Index][Thread]

Re: Destructors



 
--

On Mon, 20 Mar 2000 12:45:01   Hugh Greene wrote:
>On Wed, 15 Mar 2000, P Tucker Withington wrote:
>> ----- Original Message -----
>> From: "Chris Double" <chris@double.co.nz>
>> To: <info-dylan@ai.mit.edu>
>> Sent: Wednesday, March 15, 2000 1:00 PM
>> Subject: Re: Destructors
>> [...]
>> 
>> > The safest way of ensuring construction/destruction type idioms would
>> > be to use block/cleanup forms I think. Wrapped in a macro like the
>> > with-open-file and with-lock type macros. Maybe add a resource release
>> > in the finalizer as well in case the user of the class does not use
>> > the with-* macro, or forgets to call the cleanup function.  ...
>> 
>> Finalization is a trap.  It is probably the source of more questions (and
>> bugs) in Java than any other "feature".  Your suggestion of block/cleanup is
>> the right way to go...
>
>In fact, it just occured to me that in fact it might be even better to use
>block/cleanup but also write finalize methods which check that the
>resource has already been freed and warn you if it hasn't (and probably
>then go on to free it for you anyway). 
>
>You could either warn via something like debug-message or you could
>actually signal a <warning>.  The latter has the advantage that you could
>set up a handler to do whatever you want with the exception, including
>writing a debug-message or dropping through to the debugger to inspect
>program state.  Having said that, last I checked, FD just silently threw
>away warnings, without even printing them to "stderr".

Actually, the default handler in FD issues a debug-message.

>Not a reliable way to spot resource leaks but it might help.
>
>-- Hugh
>

Andy



MailCity. Secure Email Anywhere, Anytime!
http://www.mailcity.lycos.com