[vox-tech] not freeing heap memory

Jeff Newmiller vox-tech@lists.lugod.org
Tue, 29 Apr 2003 18:24:04 -0700 (PDT)


On Tue, 29 Apr 2003, Ken Bloom wrote:

> 
> On 2003.04.29 10:03, Peter Jay Salzman wrote:
> > when you don't free memory allocated allocated from the heap on a
> > linux
> > system, the memory is recovered after the application ends.
> > 
> > are there any operating systems where the memory is only recovered
> > after
> > a reboot?
> 
> Classic MacOS IIRC

>From the beginning, MacOS had a concept of memory "zones", so that data in
the application zone could be reclaimed when the program terminated.  
They also used the concept of memory "handles"... the value returned by
the memory allocating function was actually a pointer into an array of
pointers.  The OS reserved the right to change the pointers in the array
in order to defragment memory, unless the application "locked" the
handle.  While locked, the memory referred to by a handle could be
accessed with a pointer, but programs that locked everything typically
encountered fragmentation quickly so locking had to be minimized.

DOS had a similar mechanism to "zones" with its "arenas", but it didn't
bother with handles (since segments were such a spiffy mechanism - 
*irony*).

Windows 3.1 defined a "local heap" that was reclaimed when a program
exited, and used handles when handing out memory.  However, Windows 3.1
actually used virtual memory to deal with the local heap and program
machine code, so it was actually slightly more robust than the Mac.

The problem was that all three of these operating systems _also_ allowed
the allocation of memory outside the application-specific pools... so a
program could allocate memory outside its own zone/arena/heap and fail to
return it before exiting.  This was particularly a problem for Win3.1
because after the introduction of "386 enhanced mode" and typical memory
requirements exceeded 4MB most programmers allocated all memory from the
global heap and immediately locked every handle they received because the
local heap was still only 64K!

So I think every operating system has recognized the need to reclaim
memory when a program exits, but without (and sometimes with) memory
management hardware support programming mistakes could still cause
"global" memory leaks in the instances I am familiar with.  So I have no
examples to fit Pete's original question, but the problem was quite real
anyway.

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------