I am using a list template from the STL in BorlandC++ Builder and have a problem in that I can't get it to release the memory it uses once I reduce the size of the list. The documentation states I should do the following:

// Remove data from the list
    list<MSData>::iterator result =
        remove(MSList.begin(), MSList.end(), CompareType);
    // Delete dangling elements from the list
    MSList.erase(result, MSList.end());

The data I wish to delete is deleted but the memory that was used is not freed up. MSData is a class I generated and overrode the == operator, amongst others.

> but the memory that was used is not freed up
If you worked this out by watching task monitor or process explorer, then it wouldn't.
The program memory manager usually holds onto the memory for future memory requests from your program (which is relatively quick), rather than asking the OS each time (which can be rather slow).

Thanks for the info, I thought the memory would be given back to the memory manager for general use.

> I thought the memory would be given back to the memory manager for general use.
That's what I said - it goes back to the memory manager within the program to be used in further allocation requests your program may make.

It's all virtual memory anyway, if your program stops using blocks of memory for a while, then the OS will likely swap that memory out to disk.

This article has been dead for over six months. Start a new discussion instead.