[fpc-pascal] methods of an object to create others objects

Graeme Geldenhuys graemeg.lists at gmail.com
Mon Jul 5 23:06:02 CEST 2010


On 5 July 2010 22:03, Marcos Douglas wrote:
> The ask is:
> If a function creates, inside, a object and there is no variable to
> receive this pointer, will happen a memory leak?

Yes you will have a memory leak. Easy way to test is to enable the
heaptrc unit (compiler option -gh). On terminating the application,
the heaptrc unit will dump memory usage output to the console window.

If the object returned is a reference counted object, then I think it
will be freed (though not working with the interface instance itself
is bad practice).

Remember FPC doesn't have garbage collection like Java or .NET.  Rule
of thumb is that if you created it, you need to free it.


-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-pascal mailing list