[Malvern] Memory leakage.

Steve Cashmore mlug at cashmore.me.uk
Mon Aug 13 11:11:01 BST 2007


Geoff Bagley wrote:
> I note the recent posts which speak of the failure of some application 
> programmes, (and possibly compilers too)
> to return  no-longer-needed memory to the heap.  Is this a problem which 
> cannot happen in the case of stack-oriented
> languages such as FORTH and Postscript ?  In such cases, any cock-ups 
> with the stack would cause the prog to malfunction.

It rather depends on how the Forth system is hosted. If it's self hosted 
with no underlying OS then they typically use a very simple memory 
management system based on the Forth stack. Abuse of this will likely 
result in a crash. But memory management is performed by the application 
so at least you have control.
An OS hosted Forth may make OS calls for allocated memory from the heap. 
When the Forth system closes heap memory will be returned to the OS. 
This applies pretty well whatever language is used. But OSs also offer 
other means of claiming memory, either 'locked' or paged-in memory or 
kernel memory etc. Depending on the OS and application coordination you 
cannot guarantee this memory will be returned on exit.

Another issue occurs with fragmentation of the heap. Depending on the 
quality of the heap manager it may be more or less effective at 
coalescing returned fragments. Consequently a subsequent request for 
memory may be refused based on the heap managers inability to provide a 
contiguous chunk of the requested size. Heap management has improved in 
leaps and bounds in the last 15yrs or so but problems can still exist.
-- 
Steve






More information about the Malvern mailing list