Why does my Delphi program's memory continue to grow?
- by lkessler
I am using Delphi 2009 which has the FastMM4 memory manager built into it.
My program reads in and processes a large dataset. All memory is freed correctly whenever I clear the dataset or exit the program. It has no memory leaks at all.
Using the CurrentMemoryUsage routine given in spenwarr's answer to: http://stackoverflow.com/questions/437683/how-to-get-the-memory-used-by-a-delphi-program, I have displayed the memory used by FastMM4 during processing.
What seems to be happening is that memory is use is growing after every process and release cycle. e.g.:
1,456 KB used after starting my program with no dataset.
218,455 KB used after loading a large dataset.
71,994 KB after clearing the dataset completely. If I exit at this point (or any point in my example), no memory leaks are reported.
271,905 KB used after loading the same dataset again.
125,443 KB after clearing the dataset completely.
325,519 KB used after loading the same dataset again.
179,059 KB after clearing the dataset completely.
378,752 KB used after loading the same dataset again.
It seems that my program's memory use is growing by about 53,400 KB upon each load/clear cycle. Task Manager confirms that this is actually happening.
I have heard that FastMM4 does not always release all of the program's memory back to the Operating system when objects are freed so that it can keep some memory around when it needs more. But this continual growing bothers me. Since no memory leaks are reported, I can't identify a problem.
Does anyone know why this is happening, if it is bad, and if there is anything I can or should do about it?