Question

I am debugging my program with FastMM and it seems that a lot of the memory leaks it is reporting seem legitimate memory allocation not an actually memory leak.

For instance,

A memory block has been leaked. The size is: 20

This block was allocated by thread 0xD44, and the stack trace (return addresses) at the time was:
404902 [System.pas][System][@GetMem][3693]
406597 [System.pas][System][TObject.NewInstance][11044]
406B2A [System.pas][System][@ClassCreate][12121]
60A1D2 [CtrlObjs.pas][Ctrlobjs][TConnObj.Create][430]
61703B [Control.pas][Control][TControlMgr.FindLinks][854]
60ACB2 [CtrlObjs.pas][Ctrlobjs][TControlObject.FindLink][746]
60E2A3 [CtrlObjs.pas][Ctrlobjs][TDelayControl.EvalPulse][2105]
60E4C0 [CtrlObjs.pas][Ctrlobjs][TDelayControl.Evaluate][2193]
6102D4 [CtrlObjs.pas][Ctrlobjs][TLineControl.Evaluate][3155]
60ABF1 [CtrlObjs.pas][Ctrlobjs][TControlObject.ActiveCount][711]
6105D8 [CtrlObjs.pas][Ctrlobjs][TLineControl.ActiveCount][3261]

The block is currently used for an object of class: TConnObj

TConnObj is class that is frequently used to create an object and be destroyed when the program is not need it anymore. However, FastMM is reporting it to be actual memory leak. So, how do you tell which is which when looking at the FastMM memory leak log file?

Was it helpful?

Solution

If FastMM is reporting it as a leak then it really is a leak.

You have created an object and failed to destroy it before the program terminates. Usually this is due to a straightforward error in your code. Perhaps you omitted a try/finally to protect the object's life.

If it's a global scope object that is not being destroyed then you could simply destroy it at program termination. Or you could call RegisterExpectedMemoryLeak to indicate that you do not intend to destroy that object. But only do that when you intentionally leak an object. Don't use it to paper over a leak that is not intentional.

But the bottom line is that FastMM does not lie. If it says you are leaking, trust it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top