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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,cb73ffe253a5caf1,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!solnet.ch!solnet.ch!news-zh.switch.ch!switch.ch!cern.ch!news From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Memory management clarification Date: Tue, 26 Jul 2005 11:57:17 +0200 Organization: CERN - European Laboratory for Particle Physics Message-ID: NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sunnews.cern.ch 1122371837 27206 (None) 137.138.37.241 X-Complaints-To: news@sunnews.cern.ch User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050724 Red Hat/1.7.10-1.1.3.1.SL3 X-Accept-Language: en-us, en Xref: g2news1.google.com comp.lang.ada:3782 Date: 2005-07-26T11:57:17+02:00 List-Id: Hi, Trying to learn a bit of Ada I came across a statement that memory allocated from the pool will be implicitly reclaimed when the acces variable used to reference it goes out of scope. That's nice, but I would like to learn a bit more about the exact mechanics of this and about the guarantees that it can provide. Let's say that there is some MyType definition and this: type MyTypeRef is access MyType; 1. declare X : MyTypeRef; begin loop X := new MyType; end loop; -- infinite loop just for the sake of discussion end; Note that X does not goes out of scope when the loop is executing. Will the memory be reclaimed? When? What can be said about the memory consumption of such program? Is it bounded and guaranteed? Is it necessarily larger than without the loop (just single allocation)? 2. loop declare X : MyTypeRef; begin X := new MyType; end; end loop; What now? Is this any different from the memory management point of view? 3. declare X : MyTypeRef; begin X := new MyType; X := new MyType; X := new MyType; X := new MyType; -- ... end; When is the memory reclaimed for each allocated object? At each subsequent assignment? Or maybe at the end of the block? Or even "sometime later"? Or maybe all subsequent assignments are eliminated by compiler? 4. Is it possible to associate some function with object allocated by new, which would be called at the time (or maybe after) the object is reclaimed? Yes, I'm asking about destructors or finalizers. 5. Is it possible to "overload" new for MyType so that the X := new MyType; statement will do whatever *I* want it to do, including actual memory allocation? If yes, is it possible to hook on memory reclamation as well? 6. What about reference cycles between dynamically allocated objects? declare type ListNode; type ListNodeRef is access ListNode; type ListNode is record SomeData : Integer; Other : ListNodeRef; end record; First, Second : ListNodeRef; begin First := new ListNode; First.all.SomeData := 7; Second := new ListNode; Second.all.SomeData := 8; First.all.Other := Second; Second.all.Other := First; -- cycle end; Will the memory be reclaimed? Regards, -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/