Why does my Delphi program's memory continue to grow?

Posted by lkessler on Stack Overflow See other posts from Stack Overflow or by lkessler
Published on 2010-04-02T23:09:53Z Indexed on 2010/04/02 23:13 UTC
Read the original article Hit count: 428

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?

© Stack Overflow or respective owner

Related posts about delphi

Related posts about fastmm