From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,LOTS_OF_MONEY, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,277e9347c1aa51a6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-21 07:13:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.cwix.com!wn13feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!not-for-mail Reply-To: "James S. Rogers" From: "James S. Rogers" Newsgroups: comp.lang.ada References: Subject: Re: Finalization and Declare blocks. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: <3y%M9.73064$hK4.5968874@bgtnsc05-news.ops.worldnet.att.net> Date: Sat, 21 Dec 2002 15:13:03 GMT NNTP-Posting-Host: 12.86.34.97 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1040483583 12.86.34.97 (Sat, 21 Dec 2002 15:13:03 GMT) NNTP-Posting-Date: Sat, 21 Dec 2002 15:13:03 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:32154 Date: 2002-12-21T15:13:03+00:00 List-Id: "Stapler" 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