[fpc-devel] Interfaced Object leak in inherited Object
acmui_2004 at 163.com
Mon Jun 13 12:26:21 CEST 2005
----- Original Message -----
From: "Michael Van Canneyt" <michael at freepascal.org>
To: "FPC developers' list" <fpc-devel at lists.freepascal.org>
Sent: Monday, June 13, 2005 5:40 PM
Subject: Re: [fpc-devel] Interfaced Object leak in inherited Object
> On Mon, 13 Jun 2005, alphax wrote:
> > It seems a bug in FPC 2.0.0.(Delphi 7.1 also has this bug)
> > Assumes there is an object(not class) declaration, the object has a IInterface field.
> > If we declare another object derive from it, in the cleanup procedure of that decendant
> > leak to clear the IInterface references.
> This is normal behviour (although maybe not desirable behaviour).
> You *must* call the destructor of your object, that is why it is there:
> to clean up.
That means I must declare a destructor for the object, and in the destructor I must call dtor explicitly and clear the Interface references Like this?
TObj2 = object(TObj1)
procedure Which; virtual;
I := nil; //<* if comment out this line, the "I" field is still not cleanup *>
WriteLn('Use Object Pointer');
Obj := New(PObj2, Create);
Obj^.I := TInterfacedObj.Create();
Dispose(Obj, Destroy); //use this syntax
WriteLn('Use Object directly');
Obj.I := TInterfacedObj.Create();
I am modified the program and test again, I found if the TObj2 destructor is empty(comment out the I := nil; statement), the inteface reference still not cleanup, this is different to the TObj1, and defferent to record's finalization, is it a normal behaviour too?
More information about the fpc-devel