comp.lang.ada
 help / color / mirror / Atom feed
From: "James S. Rogers" <jimmaureenrogers@worldnet.att.net>
Subject: Re: Finalization and Declare blocks.
Date: Sat, 21 Dec 2002 15:13:03 GMT
Date: 2002-12-21T15:13:03+00:00	[thread overview]
Message-ID: <3y%M9.73064$hK4.5968874@bgtnsc05-news.ops.worldnet.att.net> (raw)
In-Reply-To: IYVM9.245693$pN3.19944@sccrnsc03

"Stapler" <spam.magnet@yahoo.com> wrote in message
news:IYVM9.245693$pN3.19944@sccrnsc03...
> I'm currently a little fuzzy on how Ada compilers handle allocation and
> de-allocation.
>
> If I declare an Abstract Data Type(a limited record for example) in the
> private part of a package, with a generic Item as one of it's elements,
> and then I "with" that package in another package, can I instantiate the
> data type without using "new" and also assume that the the Data Type will
> be automatically de-allocated at the end of the declare block?
If you create the instance within a declare block, without using "new",
the object will be deallocated upon exiting the block. The object
resides on the stack. When the block goes out of scope the stack
memory associated with that block is reclaimed.

>
> Or, within the declaration part of the declare block, could I derive the
> Abstract Data Type from Ada.Finalization.Controlled and assume the
> same?(That it will be automatically de-allocated at the end of the
> declare block.)
If you derive the data type from Ada.Finalization.Controlled, or
Ada.Finalization.Limited_Controlled, the finalization procedure will
be called when the object goes out of scope. You should override the
finalization procedure to handle deallocation.

Controlled and Limited_Controlled types do not provide automatic
garbage collection. You need to explicitly design their Finalize
procedures to deallocate memory. The advantage of Controlled and
Limited_Controlled types is that you can override the Finalize
procedure to do what you want. Finalize will be called whenever
the Controlled object goes out of scope, or whenever a new
instance of a Controlled object is assigned to an access value
for that type.
>
> I've been getting mixed messages, so I'm assuming it depends on who's
> compiler I'm using.

No, this is not a compiler issue. All Ada compilers should give you the
same behavior.

Jim Rogers





      reply	other threads:[~2002-12-21 15:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-21  8:51 Finalization and Declare blocks Stapler
2002-12-21 15:13 ` James S. Rogers [this message]
replies disabled

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