How to hide expected memory leaks in FastMM?

I have the following sample application that shows the problem:

program FalseMemLeak; uses ShareMem; var o: TObject; begin o := TObject.Create; // "good" leak RegisterExpectedMemoryLeak(o); TInterfacedObject.Create; // bad leak end. 

Now I use the replacement BorlndMM.dll and FastMMFullDebug.dll, and I get the following report:

 --------------------------- FalseMemLeak.exe: Memory Leak Detected --------------------------- This application has leaked memory. The small block leaks are: 5 - 12 bytes: TObject x 1 13 - 20 bytes: TInterfacedObject x 1 --------------------------- OK --------------------------- 

When I remove the “bad” memory leak, everything is fine and the report does not appear. But as soon as some unexpected memory leak occurs, it also lists the recorded leaks.

I initially discovered this when I looked for these Indy memory leaks and found that they were logged, but are still reported among those that are real memory leaks.

When I use the built-in ReportMemoryLeaksOnShutdown := True , it only reports a leak for TInterfacedObject .

So, is there a way to filter out a registered memory leak when using FastMM in full debug mode?


To make this clear: this is BorlndMM.dll, which comes with FastMM entries, and which says it is a replacement for one of them, and it uses FastMM4 and loads FastMM_FullDebugMode.dll. Thus, all calls to the memory manager are handled by FastMM4. But for some reason, this ignores filtering of registered leaks (which are registered in FastMM inside the replacement of BorlndMM.dll - this can be seen when debugging this DLL). Yes, reported leaks are not reported when using FastMM4.pas, but a change is not discussed.

+5
source share
1 answer

FastMM4Options.inc has the following:

 {$ifdef borlndmmdll} .... {$undef HideExpectedLeaksRegisteredByPointer} .... 

HideExpectedLeaksRegisteredByPointer is what causes the behavior you are observing. Recompile the borlandmm.dll replacement with HideExpectedLeaksRegisteredByPointer and your expected leaks will be suppressed from the leak report.

However, HideExpectedLeaksRegisteredByPointer supposed to be undefined. As to why this is so, I am not sure, but I cannot imagine this Pierre undefined by accident. In any case, it might be wise to define HideExpectedLeaksRegisteredByPointer . You can experiment with this.

+5
source

Source: https://habr.com/ru/post/1214016/


All Articles