comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: virtual destructors
Date: 22 Apr 2003 17:32:59 -0400
Date: 2003-04-22T17:32:59-04:00	[thread overview]
Message-ID: <wccfzoai5f8.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: raepa.570284$F1.79045@sccrnsc04

tmoran@acm.org writes:

> > Another question: are there any advantages in using
> > Ada.Finalization for objects that will always be dynamically
> > allocated/deallocated over simply declaring a Dispose procedure,
> The compiler will make sure Finalize is called, whereas the programmer
> will sooner or later forget to call Dispose.

But the Finalize is just doing some Unchecked_Deallocations (according
to the OP), so it doesn't really matter.  If you forget to Dispose,
then it will Dispose just before program exit, which is not really
useful.

If the Finalize were doing something important, then yes, the Ada
implementation makes sure it happens.  But for library-level access
types (which is 99.9% of all access types, I suspect), it happens very
late in the game if you don't explicitly Dispose.

I think the truth is that finalization is much more useful for stack
objects than for heap objects.  In Java, where everything's a heap
object, and deallocation is done by GC, finalization (quite a complex
feature) is nigh unto useless, which is rather a shame.  You can't do
most of the useful tricks that Ada and C++ allow, like locking/unlocking
a resource via finalization.

- Bob



  reply	other threads:[~2003-04-22 21:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-22 14:18 virtual destructors kat-Zygfryd
2003-04-22 14:27 ` Stephen Leake
2003-04-22 14:56   ` kat-Zygfryd
2003-04-22 15:45     ` kat-Zygfryd
2003-04-22 16:34       ` tmoran
2003-04-22 21:32         ` Robert A Duff [this message]
2003-04-22 17:18       ` Stephen Leake
2003-04-22 16:34         ` Simon Wright
2003-04-22 19:57           ` Stephen Leake
2003-04-22 20:19             ` Simon Wright
2003-04-22 21:23             ` Robert A Duff
2003-04-23 15:16         ` Matthew Heaney
2003-04-22 17:31       ` virtual destructors - doesn't seem to work kat-Zygfryd
2003-04-22 17:32         ` Simon Wright
2003-04-22 17:33     ` virtual destructors Matthew Heaney
2003-04-22 17:28 ` Matthew Heaney
2003-04-22 17:40   ` kat-Zygfryd
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox