Home > Mobile >  FastMM does not show leaks even if Inc file is properly set
FastMM does not show leaks even if Inc file is properly set

Time:08-24

An old project landed in my hands. It has 130000 lines of really bad code (no try/finally all exceptions swallowed, thousands of global variables). I expect thousands of memory leaks. However, FastMM4 shows nothing on shutdown. No message box, no txt log file.

I use the same FastMM settings (inc) for all other projects, it works. So, I am not suggesting FastMM (or its settings) is broken. I think just can't handle this impressive amount of leaks. A friend of mine told me that on a large project also with many leaks, it needed 5-10 minutes until FastMM generated the txt log.

Verifications:

  • FastMM is declared on the first line in DPR.
  • I manually created a line of code to generate a leak.
  • EnableMemoryLeakReporting is defined (see listing below)
  • I am in debug mode (Map file generation is set to "Detailed")

Any tips on how to get the log?


{$define UseCustomFixedSizeMoveRoutines}
{$define UseCustomVariableSizeMoveRoutines}
{$define NoDebugInfo}
{$define ASMVersion}
{$define CheckHeapForCorruption}
{$define DetectMMOperationsAfterUninstall}
{$define FullDebugMode}

  {$define RawStackTraces}
  {$define LogErrorsToFile}
  {$define LogMemoryLeakDetailToFile}
  {$define ClearLogFileOnStartup}
  {$define LoadDebugDLLDynamically}
  {$define AlwaysAllocateTopDown}
  {$define SuppressFreeMemErrorsInsideException}

{$define EnableMemoryLeakReporting}
  {$define HideExpectedLeaksRegisteredByPointer}
  {$define RequireDebuggerPresenceForLeakReporting}
  {$define EnableMemoryLeakReportingUsesQualifiedClassName}
{$define EnableMMX}
  {$define ForceMMX}

enter image description here

enter image description here

CodePudding user response:

I don't understand which settings and ini file you are talking about. FastMM4 options are driven by compiler conditionals, IIRC.

The memory leaks are not tracked by default.

You need to compile your project with the EnableMemoryLeakReporting conditional explicitly enabled.

And possibly LogMemoryLeakDetailToFile and FullDebugMode conditionals too. With FastMM_FullDebugMode.dll and FastMM_FullDebugMode64.dll libraries in your executable folder, depending on your target platform.

And enable the "map file generation" level into "Detailed" in the project options, if you want line numbers for the stack trace.

See this article and other similar as reference.

CodePudding user response:

I have found the reason: The person who wrote the code uses KillTask to terminate the program (followed by Application.Terminate). The log file is 12MB! I have to fix them. Lucky me!


Personal thoughts: when I have the solution, I was sad, and I thought maybe this was not supposed to be a post for StackOverflow. On a second thought, it is fine. We learned something today: how not to write programs :)

  • Related