comp.lang.ada
 help / color / mirror / Atom feed
From: Brad Moore <brad.moore@shaw.ca>
Subject: Re: newbie: can't read fast enough... :-)    memory leaks...
Date: Thu, 04 Sep 2014 09:36:41 -0600
Date: 2014-09-04T09:36:41-06:00	[thread overview]
Message-ID: <dG%Nv.150343$Hb3.42504@fx03.iad> (raw)
In-Reply-To: <WB_Nv.132587$oe6.88682@fx29.iad>

On 2014-09-04 8:23 AM, Brad Moore wrote:
> On 2014-09-03 11:32 PM, Jeffrey Carter wrote:
>> On 09/03/2014 09:57 PM, Brad Moore wrote:
>>>
>>>       declare
>>>          type String_Access is access String;
>>>          A, B : String_Access;
>>>       begin
>>>          A := new String'("String 1");
>>>          B := new String'("String 2");
>>>          ... -- Operate on the data.
>>>       end;
>>>       -- A and B are automatically freed here because the String_Access
>>>       -- is finalized since the scope of the declaration of the access
>>>       -- type is being exited, and finalizing an access type also
>>>       -- finalizes its collection (allocated objects designated by that
>>>       -- type).
>>>
>>> This is a nice way to free up a bunch of objects that are no longer
>>> needed, if
>>> it can be guaranteed that the objects are only needed in a nested
>>> scope. I like
>>> this better than garbage collection, because the
>>> deallocation occurs more consistently, when and where it is needed.
>>> I view this as being less error prone, if one is able to take
>>> advantage of this
>>> approach.
>>
>> Recent comments here in another thread indicate that this only works if
>> 'Storage_Size is defined for the access type.
>>
>
>
> That doesn't appear to be correct.

Looking deeper, yes, the objects of access type are finalized when the 
access type goes out of scope, but it is implementation defined whether 
the storage for the objects is reclaimed.

I wonder how many implementations are out there that do not have a 
default storage pool that reclaims the storage of a collection of an 
nested access type when the master associated with of the access type 
declaration is exited.

I'm pretty sure that GNAT does for Windows and Linux, but perhaps they 
have a minimalist runtime for certain targets where this is not needed 
or desired?



  reply	other threads:[~2014-09-04 15:36 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-03  9:38 newbie: can't read fast enough... :-) memory leaks gdotone
2014-09-03 10:17 ` Pascal Obry
2014-09-03 10:48   ` G.B.
2014-09-03 15:50     ` Pascal Obry
2014-09-03 17:28     ` Robert A Duff
2014-09-03 17:36       ` Pascal Obry
2014-09-03 19:09         ` gdotone
2014-09-03 19:19           ` gdotone
2014-09-03 19:29             ` Dmitry A. Kazakov
2014-09-03 20:19         ` Robert A Duff
2014-09-03 19:19       ` Dmitry A. Kazakov
2014-09-03 20:31         ` Robert A Duff
2014-09-04  7:18           ` Dmitry A. Kazakov
2014-09-04  4:57   ` Brad Moore
2014-09-04  5:32     ` Jeffrey Carter
2014-09-04  7:23       ` Dmitry A. Kazakov
2014-09-04 14:23       ` Brad Moore
2014-09-04 15:36         ` Brad Moore [this message]
2014-09-04 18:28           ` Robert A Duff
2014-09-05  4:58             ` anon
2014-09-05  9:45               ` Simon Wright
2014-09-05 21:54                 ` anon
2014-09-06  6:28                   ` Simon Wright
2014-09-04 15:55         ` G.B.
2014-09-04 16:43         ` Jeffrey Carter
replies disabled

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