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,b307bd75c8071241 X-Google-Attributes: gid103376,public From: "Nick Roberts" Subject: Re: newbie Q: storage management Date: 1997/05/02 Message-ID: <01bc54f6$09924480$LocalHost@xhv46.dial.pipex.com>#1/1 X-Deja-AN: 239038388 References: <5k5hif$7r5@bcrkh13.bnr.ca> Organization: UUNet PIPEX server (post doesn't reflect views of UUNet PIPEX) Newsgroups: comp.lang.ada Date: 1997-05-02T00:00:00+00:00 List-Id: Kaz Kylheku wrote in article <5k5hif$7r5@bcrkh13.bnr.ca>... > I've looked at the ISO standard and the relevant FAQ's and tutorials, but I > still need some discussion or clarification about the management of objects > obtained via ``new'', because what I have read so far seemed rather vague in > one respect. > > Whose responsibility is it to destroy these objects? The Ada 95 standard > says that an implementation is permitted to implement garbage collection, > but not required to do so. > > I know that it is possible to instantiate a generic freeing function for > explicitly destroying objects. But why is there is this lack of symmetry in the > language? On the one hand, you have a slick ``new''-expression to create > objects, but the complementary deletion operation is totally obscured. Does > this mean that explicit freeing of objects via an instance of > Unchecked_Deallocation is discouraged (due to the potential creation of > dangling references)? Is it the reponsibility of the language implementation to > automagically detect when an object is no longer reachable and do the > appropriate deallocation, even if garbage is not collected? > In Ada, an object of an access type is defined (by the language) as being deallocated, in effect, when that type goes out of scope. However, since the object cannot possibly be dereferenced (used) when its type has gone out of scope, an Ada compiler need, in practice, do nothing to deallocate the object: it can just leave the memory used up by the allocation permanently allocated (until the program terminates). The Ada compilers that I have used are old and arcane ones (for four-bit target machines, believe it or not). I gather from recent net conversations that most Ada compilers these days do not do any automatic memory reclamation ('garbage collection'), because it is not generally required. Well, I would agree wholeheartedly that in embedded applications, random garbage collection would be just a tad impractical; of course, in these applications, access types (I don't mean 'access all' types) tend not to be used anyway. However, I would assert that an Ada compiler which targets a desktop computer should provide full reclamation, no matter how much extra memory or time it costs. It seems just too impractical to me that it should do otherwise. I would welcome comments on this. Nick.