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

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Sat Oct 22 09:49:32 CEST 2011


On Sat, Oct 22, 2011 at 9:36 AM, Frank Church <vfclists at gmail.com> wrote:
> 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?

No, you got parts of it wrong:

*Free calls Destroy which releases the memory of the object itself.

*Nothing releases the memory of the pointer to the object. You don't
want to release the 4 or 8 bytes of the pointer. If you did release
it, then your application would crash when trying to read the pointer
to check if it is nil.

*Destroy implements releasing the memory of the object. Free calls Destroy.

*Setting the object to nil does just that. It changes the pointer to
the object to have the value nil (zero). It does not release the
pointer.

-- 
Felipe Monteiro de Carvalho



More information about the fpc-pascal mailing list