ignoring memory leaks using HideLeak

delphi package - automated exception handling
Post Reply
zbeleh
Posts: 4
Joined: Tue Jan 19, 2021 7:14 pm

ignoring memory leaks using HideLeak

Post 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.
viewtopic.php?f=4&t=27655

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?
Thanks!
madshi
Site Admin
Posts: 10365
Joined: Sun Mar 21, 2004 5:25 pm

Re: ignoring memory leaks using HideLeak

Post 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.
zbeleh
Posts: 4
Joined: Tue Jan 19, 2021 7:14 pm

Re: ignoring memory leaks using HideLeak

Post 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);
MadExcept.StartLeakChecking;
Post Reply