How do I find memory leaks at run time with FastMM4?

Since September 2012, there is a very simple but comfortable way to find FastMM memory leaks in Delphi applications which do not show up at program termination.This type of memory leakis normally not easy to track down, as it is caused by global objects which will be properly freed at the end of the program execution, but slowly increase their count at run time, causing resource expiration after a while. FastMM4991 introduced a new method which allows to find this type of leak.

Read the full answer on Stackoverflow.

To discover the leak at run time, you only need these steps:

  1. add a call to LogMemoryManagerStateToFile('memory.log', '') in a place where it will be called in intervals
  2. run the application
  3. open the log file with a tail program (for example BareTail), which will auto-refresh when the file content changes
  4. watch the first lines of the file, they will contain the memory allocations which occupy the highest amount of memory
  5. if you see a class or memory type constantly has a growing number of instances, this can be the reason of your leak

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s