comp.lang.ada
 help / color / mirror / Atom feed
From: stt@spock.camb.inmet.com (Tucker Taft)
Subject: Re: Does memory leak?
Date: Thu, 23 Mar 1995 22:38:13 GMT
Date: 1995-03-23T22:38:13+00:00	[thread overview]
Message-ID: <D5x07q.n57@inmet.camb.inmet.com> (raw)
In-Reply-To: 3kopao$ekg@nef.ens.fr

Duncan Sands (sands@clipper.ens.fr) wrote:

: Does Ada leak memory?  

No, but some implementations do ;-).

: ...I would like to believe it doesn't, but
: how does it manage not to (without having to use unchecked
: deallocation)?

Implementations of Ada are allowed to support automatic storage
reclamation (garbage collection) of storage allocated using
"allocators" (such as "new T") but few if any do so at this point.

Implementations of Ada are expected to automatically reclaim storage
for local variables, even variables whose size is not known
at compile-time.  This is often accomplished by using a special
mark/release heap (aka "secondary stack") for such local variables.

Note that Ada is more like C++ than Eiffel/Smalltalk in its
overall approach, since objects are by-default stack resident
rather than heap-resident.  In Smalltalk, pretty much everything
lives on the heap, and garbage collection is essential.  
(In Eiffel you can have "expanded" objects which can be 
implemented as stack-resident objects, though the
default remains non-expanded, heap-resident objects.)
In Ada, you can write very large programs that never use allocators 
or the heap.  

This "heap-free" approach will not work as well in conjunction
with Ada 95's "class-wide" types, but explicit recycling of
those objects that do need to be heap-resident can minimize the 
need for automatic garbage collection.  This approach is practical 
because not everything is on the heap -- only what needs to be is.

In Ada 95, users can implement their own storage "pools" which 
could be used to provide some degree of automatic storage reclamation 
for heap objects.  

In any case, most users of Ada who do use allocators, also use 
Unchecked_Deallocation, which is analogous to "free" of malloc/free fame.
("Free" sounds better than Unchecked_Deallocation, but it is really
the same thing.) 

Some Ada users use explicit mark/release, which is typically much 
faster, presuming it matches your application needs.  I would expect more
use of mark/release in Ada 95 now that users can implement
their own storage pools.

The other relevant new features of Ada 95 are user-defined
assignment and finalization, which are analagous to C++ copy constructors
and destructors.  These allow the programmer to get control
when copies are made, or when an object goes out of scope.
These can be used to implement automatic reference-counting-based
management of dynamic storage, which can do the job adequately 
for certain applications.

: For example, if I have a pointer to a block of memory, and I set
: that pointer to null, in simple cases I am ready to believe that
: the compiler knows I'm finished with the block... but if the
: pointer is to a complicated self-referential structure, some sort
: of black magic seems needed to work out whether I'm really
: finished with that structure or not.  Can this truly be done
: efficiently?

Most (all?) current Ada compilers do not provide garbage collection.
Hence setting a pointer to null will not cause any automatic
storage reclamation in such implementations.

Now that general purpose (though some will say potentially "dangerous")
language-independent "conservative" garbage collectors are available,
I would expect more of them will be integrated with Ada implementations.

True "exact" garbage collection can also be implemented in Ada, but
thus far the market demand for it has not matched the expense of
implementation.  It may be that the GNU Modula-3 "exact" garbage collection
support could be adapted to work with the GNU NYU Ada 95 compiler (GNAT).

: You can see that I know nothing about how garbage collection works,
: and precious little about what Ada requires for memory management.
: I suspect I'm not the only one.  If someone could demystify all this
: for me, I would be very grateful...

I hope the above helps a little.

The topic of storage management, and the various religious and 
technical battles associated therewith, can expand to fill whatever
amount of time you have available, so beware...

: Thanks a lot,

: Duncan Sands.

-Tucker Taft   stt@inmet.com
Intermetrics, Inc.



  parent reply	other threads:[~1995-03-23 22:38 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-03-22  9:06 Does memory leak? Duncan Sands
1995-03-22 12:04 ` Fred J. McCall
1995-03-23  0:37 ` Robert I. Eachus
1995-03-23 13:54   ` Arthur Evans Jr
1995-03-23 16:23     ` Robert I. Eachus
1995-03-24 21:08   ` Norman H. Cohen
1995-03-28  0:00     ` Theodore Dennison
1995-03-31  0:00     ` Kent Mitchell
1995-03-23  2:08 ` T. Owen O'Malley
1995-03-24 11:44   ` Robert Dewar
1995-03-27 14:01     ` Theodore Dennison
1995-03-29  0:00       ` John DiCamillo
1995-03-30  0:00         ` Theodore Dennison
1995-03-30  0:00         ` Robb Nebbe
1995-03-30  0:00       ` Henry Baker
1995-04-04  0:00         ` John Baker
1995-04-05  0:00           ` Ray Toal
1995-04-05  0:00           ` Pat Rogers
1995-04-05  0:00           ` Sverre Brubaek
1995-04-05  0:00           ` Tucker Taft
1995-04-06  0:00             ` Norman H. Cohen
1995-04-07  0:00               ` Tucker Taft
1995-03-30  0:00   ` Robert I. Eachus
1995-03-23 22:38 ` Tucker Taft [this message]
1995-03-24  1:57 ` Henry Baker
1995-03-24 17:30   ` Larry Kilgallen, LJK Software
1995-03-26  0:00     ` Henry Baker
1995-03-27 15:19     ` Norman H. Cohen
1995-03-27 14:35   ` Kennel
1995-03-24 12:29 ` Mike Meier
1995-03-24 10:46   ` Fred J. McCall
1995-03-24 15:44   ` David Weller
1995-03-25  1:55   ` kkrieser
  -- strict thread matches above, loose matches on Subject: below --
1995-03-27  9:36 Duncan Sands
replies disabled

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