comp.lang.ada
 help / color / mirror / Atom feed
From: "Marc A. Criley" <mcq95@earthlink.net>
Subject: GNAT memory leak in compiled code (3.13p/Linux)
Date: Wed, 17 Jul 2002 00:48:25 GMT
Date: 2002-07-17T00:48:25+00:00	[thread overview]
Message-ID: <3D34BF92.BAB26BA3@earthlink.net> (raw)

The appended program, when compiled with GNAT 3.13p on Linux (RedHat
6.2) experiences a memory leak.  The offending line contains an implicit
dereference that occurs when assigning to the Buf array slice.

Does this leak occur in later versions of GNAT?  Or on other platforms?

The way I observed the memory leak occurring was by running the
executable in one window and using the following Linux command in
another:

top -bq | grep mem_leak

The fifth column is the total process size, which can be observed to
continuously grow as the program runs.

(Note to Robert Dewar:  If this memory leak is present in later versions
of GNAT, a bug report will of course be submitted to ACT via the
appropriate mechanism.)

Marc A. Criley, Consultant
Quadrus Corporation
www.quadruscorp.com

-------------------------------------------------------------------------

with Ada.Strings.Unbounded;
use  Ada.Strings.Unbounded;

procedure Mem_Leak is

   type Us_Uc_Array is array (Natural range <>) of Unbounded_String;

   type Us_Uc_Array_Ptr is access Us_Uc_Array;

   Buf : Us_Uc_Array_Ptr;

   Count : Natural := 0;

   procedure F(S : Us_Uc_Array) is
   begin
      -- The following line results in a memory leak when this program
      -- is compiled with GNAT 3.13p on Linux.
      Buf(1..S'Length) := S;

      -- Comment out the above line, and uncomment the following to
      -- see the program run with no memory leak.
      -- Buf.all(1..S'Length) := S;
   end F;

begin
   Buf := new Us_Uc_Array(1..10_000);
   for I in 1..50 loop
      F((1..110 => To_Unbounded_String("Hello")));
      delay 0.5;
   end loop;
end Mem_Leak;



             reply	other threads:[~2002-07-17  0:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-17  0:48 Marc A. Criley [this message]
2002-07-17  5:28 ` GNAT memory leak in compiled code (3.13p/Linux) Simon Wright
2002-08-13 11:36   ` Preben Randhol
2002-07-17  8:37 ` Fabien Garcia
2002-07-20  2:51 ` Dave Taylor
replies disabled

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