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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5653f0bd43045b85 X-Google-Attributes: gid103376,public From: tmoran@bix.com Subject: Re: garbage collection Date: 1999/08/18 Message-ID: <1ZCu3.301$26.56649@typhoon-sf.snfc21.pbi.net>#1/1 X-Deja-AN: 514310966 References: <7pe93j$ehg$1@dailyplanet.wam.umd.edu> X-Complaints-To: abuse@pacbell.net X-Trace: typhoon-sf.snfc21.pbi.net 935001021 206.170.24.107 (Wed, 18 Aug 1999 11:30:21 PDT) Organization: SBC Internet Services NNTP-Posting-Date: Wed, 18 Aug 1999 11:30:21 PDT Newsgroups: comp.lang.ada Date: 1999-08-18T00:00:00+00:00 List-Id: > If an implementation doesn't provide garbage collection then that > storage is forever lost, is that correct? No. When the access type goes out of scope there is clearly no way the storage can be on the target end of a pointer, so the implementation should free that storage. With the 'Storage_Size attribute on the access type, "the storage for the pool is reclaimed when the master containing the declaration of the access type is left". If that's not soon enough, you have several options, including: 1) Ada.Unchecked_Deallocation (the equivalent of "free"), if you are careful not to deallocate and later refer to the same storage. 2) Use a controlled type so your Finalize routine can recycle storage. 3) Do your own storage management for the relevant types using the Storage_Pool facility. See Barnes, section 21.4 for a good discussion of storage management. 4) The most straightforward way, as has been pointed out, is not to use "new" unnecessarily. Since you can declare dynamically sized things inside a subroutine, and can nest subroutines, storage that is allocated in a stack-like (first allocated is last deallocated) style can normally be handled with simple declarations, without the overhead or dangers of "new". With tasks, you can even have several separate stack-like allocations going on at once.