Re: IdComponent memory leak ?

Giganews Newsgroups
Subject: Re: IdComponent memory leak ?
Posted by:  Grahame Grieve (grraha…
Date: Mon, 8 Dec 2003

yarod wrote:

> Hello,
> In IdComponent.pas, a critical section is created in the
> initialization. But the finalization does not free it and contains a
> strange comment.
> My memory manager sees it as a memory leak. Can someone explains how
> freeing critical section will cause a GPF (or AV) ?
> --- 8< ---
> initialization
> GStackCriticalSection := TCriticalSection.Create;
> finalization
> // Dont Free. If shutdown is from another Init section, it can cause
> GPF when stack
> // tries to access it. App will kill it off anyways, so just let it
> leak //FreeAndNil(GStackCriticalSection);
> end.

There's no control over finalization order. The critical section can
be Freed and then other units refer to it. It has been judged that it's
better to leak a single critical section at process close than risk
access violations.

If the indy code is in a dll, then it's a leaking critical section
per load/unload of the dll. if you are writing a dll, and it's a
problem, then you can free the critical section. Then, if you get
an access violation, you know why you got it.




In response to

IdComponent memory leak ? posted by yarod on Wed, 03 Dec 2003