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

Re: Destructors



I agree the block approach is elegant, for file handles I'd definitely do
it, but I'm talking about objects with a lifespan beyond the function that
instantiates them: wrappers for an OS-managed window object that needs
deallocation.
Calling an explicit destructor or a "deallocate" method on the close event
has the same effect, so, yes, deallocating on close is the way to go.
I worry about a finalize() method that behaves differently on a global
setting...

- Rob.

> From: Barry Margolin <barmar@bbnplanet.com>
> 
> In article <03c401bf8eb8$435f50f0$8d53e6d8@curl.com>,
> P Tucker Withington <ptw@callitrope.com> wrote:
>> 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...
> 
> It's also the right way to go in the original poster's application.  He
> mentioned that this is for cleaning up foreign resources related to window
> system objects.  Presumably, the application knows precisely when it has
> removed the window from operation -- they're not expected to stay on the
> screen and just disappear spontaneously when GC notices them.  So when the
> application deletes the window, it knows that it's appropriate to call the
> foreign interface to delete its data.  The Dylan data can be left around
> for GC to clean up.




Follow-Ups: References: