Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knowing where memory is being allocated using FastMM

Tags:

delphi

fastmm

I am trying to debug memory usage in a large application using Delphi 7. I was able to installed fastmm debug full dll and with it solve some leak problems.

I also installed the memory usage tracker, allowing me to see which blocks were allocated and of what size they are.

My question is, is there a way to find out where the blocks were allocated? I know it is possible because if the memory wasn't freed a stack trace gets printed. Is there a way to 'poke' at fastmm to get it to print the stack trace for a given allocation?

Side question: if the start address of an allocation is known, is there a way to find out which class the object is? (assuming that the allocation was for a object.

like image 304
wmercer Avatar asked Jan 18 '13 01:01

wmercer


1 Answers

You can either:

  • try to use LogAllocatedBlocksToFile procedure. If its ALastAllocationGroupToLog param is less than AFirstAllocationGroupToLog or is zero, then all blocks along with their allocation call stacks are logged. However, if your app has many memory allocations, prepare to long waiting. I experienced about 4 hrs wait time and 1.5Gb resulting file. (Side-note: use glogg to view such large files)
  • modify FastMM4.pas so implementation's LogCallStack will be visible in interface. Or you can try to use it directly from FastMM_FullDebugMode.dll

On the side question: try to use DetectClassInstance function.

like image 94
Serhii Kheilyk Avatar answered Nov 15 '22 00:11

Serhii Kheilyk