a Free procedure call doesn't free (and nil) an object

hi everyone,

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);
     inherited Create(AOwner);
     ... several initializations including OnTimer affectation ...

destructor TPopUpCampagne.destroy;
     ... stuff to free memory...

     inherited destroy;

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...
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

instead of

if Assigned(Mytimer) then


if Assigned(Mytimer) then

meikl ;-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
just for eplanation

>the problem is that after the free call, the variable MyTimer isn't
>Nil - as expected !

the referenceVariable is never set to nil after calling the free-method,
thats a normal bahaviour, you as developer have to care about this

meikl ;-)
btw. your timer is freed
fsurferAuthor Commented:
Thanks for the answer !

it works perfectly !

i've always believe that free was doing a FreeAnd Nil....hmmmm there're always things to learn :)

glad to helped you ;-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.