----- Original Message -----
From: Nigel Tavendale <[EMAIL PROTECTED]>
To: Multiple recipients of list delphi <[EMAIL PROTECTED]>
Sent: Monday, 24 May 1999 17:39
Subject: Re: [DUG]: Thread Memory Leak


> Nic,
>
> The Call tbl1.Free does not set tbl1 to nil.
>
> i.e the following code at the end of the execute procedure

> tbl1.Free;
> if tbl1<>nil then bDestroyed:=False else bdestroyed:=True;
> will always have bDestroyed:=False at the end.
> Will the Delphi Memory Manager release the memory eventually or will it
only do
> it if Thew App is shut down (not good for a service).

The setting of the Instance pointer to nil is not necessary to
release the instance.  In fact .free for any object does not set the
instance pointer to nil, it just releases the instance space allocated
within
the memory manager after calling the destroy destructor.

>  Calling Free again results in an access violation so I can't do that.

The reason is that the pointer is not nil so the .free tries to use the
instance
illegally pointed to. Delphi does not have any dereference assignment so
a method cannot write to the instance pointer that initiated it.

Really you should do the following if you want to check the value of the
instance
pointer post-destroy.

InstancePointer.Free;
InstancePointer := nil;

so that later in your code using 'if InstancePointer<>nil then ...' will not
give an
invalid result.  The fact that the destructors cannot write to the instance
pointer
is perhaps a shortcoming in delphis OOP implementation but it is the most
common flaw.

Another one is the delegation mechanism that does not return the instance
pointer
of the delegating interface but instead the delegated interface making a
return
casting impossible and requiring a lot of fix-it code to tidily implement
reference
counting in delegation interfaces.

Have you tried instancing the thread twice consecutively to see if the
memory
is really leaking or the memory manager is just delaying returning the
memory to
the OS until a later time...

--
Aaron@home


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to