comp.lang.ada
 help / color / mirror / Atom feed
From: "Björn Persson" <spam-away@nowhere.nil>
Subject: Re: How to properly clean up an extended, generic structure?
Date: Sun, 09 Jul 2006 14:49:11 GMT
Date: 2006-07-09T14:49:11+00:00	[thread overview]
Message-ID: <HH8sg.8269$E02.2504@newsb.telia.net> (raw)
In-Reply-To: <44b107b7$0$3629$4d3efbfe@news.sover.net>

Peter C. Chapin wrote:
> I've created a procedure Destroy_Tree that uses an instance of 
> Ada.Unchecked_Deallocation to remove all the nodes in a given tree. 
> Destroy_Tree is meant to be used when a tree is no longer needed and it 
> serves the role of a destructor (using C++ terminology). It occurs to 
> me, though, that Item_Type might have its own clean up needs.

You need controlled types. Derive your tree type from 
Ada.Finalization.Controlled, and instead of Destroy_Tree write a 
procedure Finalize, overriding the Finalize that's declared in 
Ada.Finalization. Finalize will then be executed automatically when the 
object is destroyed.

Item types that need cleaning up should also be controlled. Each item 
will then be finalized when its tree node is finalized.

-- 
Bj�rn Persson                              PGP key A88682FD
                    omb jor ers @sv ge.
                    r o.b n.p son eri nu



  parent reply	other threads:[~2006-07-09 14:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-09 13:42 How to properly clean up an extended, generic structure? Peter C. Chapin
2006-07-09 14:29 ` jimmaureenrogers
2006-07-09 14:33 ` Ludovic Brenta
2006-07-09 16:21   ` Peter C. Chapin
2006-07-09 14:49 ` Björn Persson [this message]
2006-07-09 14:57 ` Georg Bauhaus
2006-07-09 19:46 ` Jeffrey R. Carter
2006-07-10  7:38   ` Jean-Pierre Rosen
replies disabled

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