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.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to