a Free procedure call doesn't free (and nil) an object
Posted on 2003-10-22
i have the following problem :
i've created a TTimer descendent the following way :
TMyTimer = Class(TTimer)
... various variables and TList Objects...
constructor Create(aowner : TComponent);override;
destructor destroy; override;
var MyTimer : TMyTimer;
constructor TPopUpCampagne.Create(AOwner : Tcomponent);
... several initializations including OnTimer affectation ...
... stuff to free memory...
then, further in the source code, i do the following (i want to destroy MyTimer to re-create it - instead of updating its data) :
if Assigned(Mytimer) then
the problem is that after the free call, the variable MyTimer isn't Nil - as expected ! but is still pointing to an existing object (and then my program throws an exception on another operation).
i've run the debugger and all the free calls in the object hierarchy are done.
Does anyone have an idea about what's happening ? and does anyone have a workaround ?
i could recreate the variable with the MyTimer:=TMyTimer.Create(Nil); but then i would have a memory leak...
thanks in advance,
PS : i put 150 points, cause it's important and i need a quick answer...