[fpc-devel] Ansistring and General Memory Management - Questions

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Feb 14 17:22:33 CET 2007

On 14 feb 2007, at 17:14, Jason P Sage wrote:

> If I allocate a large number of ansistrings of random lengths, change
> lengths, and then set them all to empty like this: MyAnsi:='' Does  
> the heap
> release all that memory or does it hang on to it to "reuse" the  
> various
> "chunks" that are not in use when appropriate?

It may hang around for a while. Whether or not it does depends on  
many different factors, including the size of the block (blocks with  
similar small sizes are allocated from pools, and a pool is only  
released back to the OS if all blocks of a pool have been freed --  
although one empty pool is always kept in order to avoid a border  
condition where allocating/freeing a single block causes constant  
allocating and freeing of a block from/to the OS).

> Note: I'm aware of heap trace but the nature architecture my  
> project just
> does not agree with heap trace. Certain things I do purposely it  
> mistakes as
> an error and these same "constructs" run leak proof in other  
> applications.

Things which are flagged as errors by heaptrace are not leaks, but  
writing past the boundaries of allocated memory blocks. This may also  
lead to memory leaks due to corruption of the memory manager's  
internal data structures.


More information about the fpc-devel mailing list