Page 1 of 1

ignoring memory leaks using HideLeak

Posted: Sun Jan 31, 2021 1:10 am
by zbeleh
There seems to be a known memory leak when it comes to Windows and critical sections.
Namely, the same InitializeCriticalSection leak from FireDAC's sqlite gets reported exactly 12 times, even if i repeat the same operation more often than that; as if the resources are kept for later use.

I would like to remove those leaks from leaks report, but have no idea how to.

In this older thread, the following syntax seemed to have been implemented, yet using it gives a compilation error.

Code: Select all

function HideLeak (someClass: TClass; count: integer) : boolean; overload;
assuming it did exist, I would also have to 'uses' whatever Delphi unit defining the type "InitializeCriticalSection", which i guess is no problem.

i did succeed hiding that leak, by wrapping the troublesome "FireDAC connection.connect" line with "StopLeakChecking" and "StartLeakChecking", though i don't know how satisfactory this approach is.

Attempting to use the available HideLeak function elsewhere to get familiar with it,

Code: Select all

vThread := TpMyThread.Create (@vCount);
MadExcept.HideLeak (vThread);
the reported message changed but did not go away.

Any ideas?

Re: ignoring memory leaks using HideLeak

Posted: Sun Jan 31, 2021 7:49 am
by madshi
You need to add madExcept to your uses class to be able to call HideLeak. Hope that helps?

If ignoring the leak this way doesn't work, you can instead hide it by using the HideLeak overload with a callstack.

Re: ignoring memory leaks using HideLeak

Posted: Sun Jan 31, 2021 2:47 pm
by zbeleh
My bad, something must have gone funny:
Reinstalling madexcept, all the overloaded functions are now available.

However, the issue I was facing was due to the runtime call to StartLeakChecking.
Any prior call to HideLeak was being ignored.
Swapping the two lines such that StartLeakChecking is the first invoked function, the leak is now ignored correctly.

Code: Select all

MadExcept.HideLeak(TMyThread, 1);