[fpc-pascal] methods of an object to create others objects
Martin
fpc at mfriebe.de
Mon Jul 5 22:39:03 CEST 2010
On 05/07/2010 21:26, Marcos Douglas wrote:
> If I have a variable myObj, I can do this:
> someObj := myObj.createObj;
>
> This is the same:
> someObj := TsomeObject.create;
>
> Rigth?
>
> But if a remove the variable *someObj* and call like this:
> myObj.createObj; // I _removed_ the *someObj* here!!!
>
> What will happen with the "result" variable? Is it released by the compiler?
>
>
that is the same as if you wrote
TsomeObject.create;
without assigning the created object to a variable. Both cause a memory
leek.
Mind you just because "Create" is a constructor does not protect it from
being called without using the result.
Martin
More information about the fpc-pascal
mailing list