comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeff C r e e.m" <jcreem@yahoo.com>
Subject: Re: Ada memory management?
Date: Thu, 07 Oct 2004 11:17:10 GMT
Date: 2004-10-07T11:17:10+00:00	[thread overview]
Message-ID: <VA99d.348738$Fg5.32069@attbi_s53> (raw)
In-Reply-To: pan.2004.10.07.10.41.56.495730@stephenthomas.uklinux.net


"Stephen Thomas" <vianews@stephenthomas.uklinux.net> wrote in message 
news:pan.2004.10.07.10.41.56.495730@stephenthomas.uklinux.net...
> On Thu, 07 Oct 2004 12:00:42 +0200, Christoph Karl Walter Grein wrote:
>
>> procedure Does_This_Leak is
>>     type Int_Ptr is access Integer;
>>     ptr: Int_Ptr;
>> begin
>>     ptr := new Integer;
>> end Does_This_Leak;
>>
>> Of course this leaks, and imagine how much!
>
> Actually, no it shouldn't, not on a halfway-decent implementation.
> Logically speaking, a storage pool for items accessed via values of
> an access type has the same lifetime as the access type itself. In
> the above example, a new storage pool for Int_Ptr is created on
> entry to Does_This_Leak, and is removed on exit.
>
> Stephen
> -- 


Stephen is correct...But just to be clear (because this is where people (not 
Stephen) get confused is that the following
(much more common construct) would leak unless unchecked_deallocation is 
used.

package body Like_A_Sieve is

     type Int_Ptr is access Integer;

procedure Does_This_Leak is
     ptr: Int_Ptr;
begin
     ptr := new Integer;
 end Does_This_Leak;

end Like_A_Sieve;

It is a rare (though still useful) construct to be able to get away with 
having the pointer type declaration totally within a short lived procedure.

Sieve 





  reply	other threads:[~2004-10-07 11:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-07 10:00 Ada memory management? Christoph Karl Walter Grein
2004-10-07 10:41 ` Stephen Thomas
2004-10-07 11:17   ` Jeff C r e e.m [this message]
2004-10-07 14:22   ` Georg Bauhaus
2004-10-07 14:51     ` Stephen Thomas
2004-10-07 16:23     ` Larry Kilgallen
2004-10-07 18:35       ` Frank J. Lhota
2004-10-07 12:00 ` Martin Krischik
  -- strict thread matches above, loose matches on Subject: below --
2004-10-07 11:31 Christoph Karl Walter Grein
2004-10-07 11:15 Christoph Karl Walter Grein
2004-10-07 12:01 ` Stephen Thomas
2004-10-07  9:39 matthias_k
2004-10-07 12:06 ` Martin Krischik
2004-10-07 17:24 ` Nick Roberts
2004-10-07 19:04   ` Luke A. Guest
replies disabled

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