[fpc-pascal] Where and Why is there a memory leak?

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Wed Sep 6 12:07:22 CEST 2017


On 2017-09-06 10:55, Graeme Geldenhuys wrote:
> On 2017-09-06 10:41, Sven Barth via fpc-pascal wrote:
>> I think THook needs to derive from TAggregatedObject, cause that couples
>> the reference counting to that of the controlling instance.
> 
> That seems to be heading in the right direction, but such a change on
> its own doesn't seem to solve the two memory leaks either. I'll test
> under Delphi XE which can report memory leaks to see what it does


Testing with Delphi XE - simply by changing THook to descend from 
TAggregatedObject. Under Delphi it also still reports a memory leak.


> Either way, modifying the example to use a getter method AND
> TAggregatedObject, I managed to get rid of both memory leaks. Here is
> the working [memory leak free] code now:

Under Delphi XE, that was the only way to get rid of the memory leaks too.

So it seems for delegation and using "implements" you are forced to use 
a getter method and object variable (not interface reference variable) - 
under both FPC and Delphi. At least they are consistent. ;-)


ps:
   For those that didn't know.... Since Delphi 2006, add

       ReportMemoryLeaksOnShutdown := True;

   in your *.dpr file to enable memory leak detection.


Regards,
   Graeme

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp



More information about the fpc-pascal mailing list