views:

335

answers:

4

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?

+1  A: 

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.

Wouter van Nifterick
I have tried breakpoints, but it never breaks. I looks like the initialization/finalization section is the only code that is run.I'm doing a massive grep now, to see if I can find anything.
Vegar
A wide grep found the used unit!
Vegar
+2  A: 

Look at Uses in your .dpr Use cnPack (cnPack.org) and select 'Uses Cleaner' to remove units not referenced

ibandyop
Another option to do this is Icarus, a free subset of Pascal Analyzer: http://www.peganza.com/#ICARUS
Bruce McGee
wow. Have heard about cnPack, but never tried it out. That has to be changed! :-) Thanks.
Vegar
+6  A: 

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.

Smasher
+2  A: 

There's a lot about this on the 'net, although it is scattered. It alo depends on whether you are using Indy 9 (with D7) or later. It's plauged me too. For Indy 9 I did the following in IdComponent.pas:

initialization
  GStackCriticalSection := TCriticalSection.Create;

  // BJF Starts
  //RegisterExpectedMemoryLeak(GStackCriticalSection);
  // BJF Ends

finalization
  // Dont Free. If shutdown is from another Init section, it can cause GPF when stack
  // tries to access it. App will kill it off anyways, so just let it leak

  // BJF has removed comments
  FreeAndNil(GStackCriticalSection);
end.

But note that you must put a path to the Indy source in the library path. I believe that Indy 10 is fixed in this respect. Brian

Brian Frost