[fpc-pascal] Memory leak or object destruction?
Michael Van Canneyt
michael at freepascal.org
Thu Feb 3 00:28:35 CET 2011
On Thu, 3 Feb 2011, Bo Berglund wrote:
> I am curious as to how FPC handles the following situations:
>
> var
> MyObj: TsomeObject;
> begin
> MyObj := TsomeObject.Create;
> // do some processing
> MyObj := NIL;
> end;
>
> Will this create a memory leak or will FPC fnd by reference counting
> that nothing references the object memory and dispose of it?
It will create a memory leak (as in Delphi).
>
> If the latter, will the disposal call the object's destructor or not?
>
> next:
>
> var
> MyObj: TsomeObject;
> begin
> MyObj := TsomeObject.Create;
> // do some processing
> end;
>
> What happens here where the local variable MyObj gets out of scope,
> again with the reference to object memory disappearing?
> Memory leak or object destruction?
Memory leak. Class instances that are created must also be destroyed.
100% the same as in Delphi.
Michael.
More information about the fpc-pascal
mailing list