[Lazarus] Difference between FreeThenNil and FreeAndNil

Mattias Gaertner nc-gaertnma at netcologne.de
Wed Apr 27 21:07:55 CEST 2011




 Alexander Klenin <klenin at gmail.com> hat am 27. April 2011 um 18:46 geschrieben:

 > On Thu, Apr 28, 2011 at 02:14, Graeme Geldenhuys
 > <graemeg.lists at gmail.com> wrote:
 > >
 > > >From that bug report it looks like a bug in TAChart, not in
 > > FreeAndNil(). I have written a crap load of components in my time,
 > > including composite components, and never had a problem with freeing
 > > children or subcomponents. You just need to do it in the right order,
 > > and obviously not reference something that is already free'd.> >> 

 > That is quite possible, but neither me nor Martin was unable to find it.
 > I'd appreciate any specific insight if you have it.
FreeThenNil is useful for variables like 'Application', which destructor
triggers complex things and/or when the variable is used at a lot of places.
During the destruction Application is still valid, so that all components can
shut down cleanly. For example they can unregister their handlers.
 
But FreeThenNil is more limited than FreeAndNil. For example you can not use it
with multithreading, because of the small step between freeing the memory and
setting the variable to nil.
 
 
Mattias
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110427/51a770ae/attachment-0001.html>


More information about the Lazarus mailing list