Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi: memoryleak in IdStack, but who uses IdStack?

FAstMM reports a memoryleak from a TIdCriticalSection in IdStack.pas. I understand this is a intentional leak, that is documented in the code.

What I do not understand, is why IdStack is included in my project. How can I find out what unit pulls it in?

Is there a way of excluding this leak from the report, using the version of fastmm that comes with delphi 2007?

UPDATE: Is there a way of finding all the pas-files included in a build?

like image 238
Vegar Avatar asked Aug 13 '09 09:08

Vegar


People also ask

Can memory leak occur in stack?

Stack memory leaks occur when a method keeps getting called but never exits. This can happen if there is an infinite loop or if the method is being called with different data each time but the data is never used. Eventually, the stack will fill up and the program will run out of memory.

How do I find a memory leak in Delphi?

All that it takes to start working with it is add a single line in your project: ReportMemoryLeaksOnShutdown := True; And voilà, your application will report all memory leaks when it shuts down. If there are leaks at the end of your application, a dialog will be displayed showing all the leaks.

How do you pinpoint memory leaks?

To find a memory leak, look at how much RAM the system is using. The Resource Monitor in Windows can be used to accomplish this. In Windows 8.1 and Windows 10: To open the Run dialogue, press Windows+R, then type "resmon" and click OK.

Why memory leak is called leak?

Memory was shared between any running jobs and was called a "pool" of memory after things like motor pools, secretarial pools, and similar. When a job (program) caused memory to become inaccessible, that memory "leaked" out of the pool.


2 Answers

The Delphi FastMM memory manager provides a method

function RegisterExpectedMemoryLeak(P: Pointer): boolean;

So, if you've found the unit and it turns out that you cannot remove it, you can use this method to supress a memory leak warning.

like image 149
jpfollenius Avatar answered Sep 29 '22 20:09

jpfollenius


All Indy units have an 'Id' prefix, so check if you have any of those in your uses clauses.

Another way might be to place a breakpoint in TIdStack.create(). Eventually, the guilty one will show up in the call stack.

like image 42
Wouter van Nifterick Avatar answered Sep 29 '22 21:09

Wouter van Nifterick