Is there a way to programmatically tell if particular block of memory was not freed by FastMM?
Posted
by
Wodzu
on Stack Overflow
See other posts from Stack Overflow
or by Wodzu
Published on 2012-01-09T07:26:34Z
Indexed on
2012/03/26
11:30 UTC
Read the original article
Hit count: 292
I am trying to detect if a block of memory was not freed. Of course, the manager tells me that by dialog box or log file, but what if I would like to store results in a database? For example I would like to have in a database table a names of routines which allocated given blocks.
After reading a documentation of FastMM I know that since version 4.98 we have a possibility to be notified by manager about memory allocations, frees and reallocations as they occur. For example OnDebugFreeMemFinish
event is passing to us a PFullDebugBlockHeader
which contains useful informations.
There is one thing that PFullDebugBlockHeader
is missing - the information if the given block was freed by the application.
Unless OnDebugFreeMemFinish
is called only for not freed blocks? This is which I do not know and would like to find out.
The problem is that even hooking into OnDebugFreeMemFinish
event I was unable to find out if the block was freed or not.
Here is an example:
program MemLeakTest;
{$APPTYPE CONSOLE}
uses
FastMM4, ExceptionLog, SysUtils;
procedure MemFreeEvent(APHeaderFreedBlock: PFullDebugBlockHeader; AResult: Integer);
begin
//This is executed at the end, but how should I know that this block should be freed
//by application? Unless this is executed ONLY for not freed blocks.
end;
procedure Leak;
var
MyObject: TObject;
begin
MyObject := TObject.Create;
end;
begin
OnDebugFreeMemFinish := MemFreeEvent;
Leak;
end.
What I am missing is the callback like:
procedure OnMemoryLeak(APointer: PFullDebugBlockHeader);
After browsing the source of FastMM I saw that there is a procedure:
procedure LogMemoryLeakOrAllocatedBlock(APointer: PFullDebugBlockHeader; IsALeak: Boolean);
which could be overriden, but maybe there is an easier way?
© Stack Overflow or respective owner