[fpc-pascal] How are Assigned, Free, Nil and Destroy related?

Frank Church vfclists at gmail.com
Sat Oct 22 09:36:22 CEST 2011


On 22 October 2011 08:14, Ludo Brands <ludo.brands at free.fr> wrote:

> > Nil is not a routine, it is a value, it means that the object
> > is empty, it does not exist / is not allocated. Nil in
> > existing implementations that I know is represented by the value zero.
> >
> > The typical life-cycle of a object is:
> >
> > MyObject := TMyObject.Create;
> > try
> >   MyObject.DoSomething();
> > finally
> >   MyObject.Free;
> > end;
> >
>
> One pitfall: the variable MyObject before MyObject := TMyObject.Create; is
> undefined and not necessarily nil. Variables are not initialized by default
> and can contain anything. In general, MyObject.Free does not set MyObject
> to
> nil neither.  Good practice is to initialize pointer variables to nil and
> resetting them to nil after freeing them whenever assigned() or <>nil is
> going to be used.
>
>
Does that mean that Free itself reclaims the memory used by the object's
fields and properties but does not release the memory used by the TObject or
pointer itself, where as setting it to nil or executing Destroy does, or
does Destroy do something different?

Ludo
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



-- 
Frank Church

=======================
http://devblog.brahmancreations.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20111022/dc4c1de8/attachment.html>


More information about the fpc-pascal mailing list