Re: Allocators and memory reclamation



On Jan 28, 8:49 am, Maciej Sobczak <see.my.homep...@xxxxxxxxx> wrote:

procedure Foo is
   type Int_Ptr is access Integer;
   P : Int_Ptr;
begin
   P := new Integer;
   P := new Integer;
   P := new Integer;
end Foo;

procedure Main is
begin
   loop
      Foo;
   end loop;
end Main;



To avoid memory leak, rewrite as...

with Ada.Unchecked_Deallocation;

type Int_Ptr is access Integer;
procedure Free is new Ada.Unchecked_Deallocation( Integer,
Int_Ptr );

procedure Foo is
P : Int_Ptr;
:
begin
P := new Integer;
:
Free( P );
:
end Foo;

procedure Main is
begin
loop
Foo;
end loop;
end Main;
.