Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Memory leak using _beginthread and TerminateThread

105 views
Skip to first unread message

José Luis Lombana Aramendía

unread,
Oct 18, 1999, 3:00:00 AM10/18/99
to

Hello,

I´m developing an application that checks the state of a certain
number of threads. Sometimes any or all threads fails, and then
is necessary to kill them; for doing this, I use TerminateThread.
After this I restart each thread, using _beginthreadex. This works,
but I have virtual and physical losses; and I suspect that the problem
is caused by using these functions.

Anyone can help me?.

Thanks in advance.

--
----------------------------------------------------------------------------
-------------
José Luis Lombana Aramendía jlom...@ts.es

Telefónica Sistemas
C/. Sor Ángela de la Cruz 3, 6ª planta
28020 MADRID
----------------------------------------------------------------------------
-------------

Didier CASSEREAU

unread,
Oct 21, 1999, 3:00:00 AM10/21/99
to José Luis Lombana Aramendía

"José Luis Lombana Aramendía" wrote:

> Hello,
>
> I´m developing an application that checks the state of a certain
> number of threads. Sometimes any or all threads fails, and then
> is necessary to kill them; for doing this, I use TerminateThread.
> After this I restart each thread, using _beginthreadex. This works,
> but I have virtual and physical losses; and I suspect that the problem
> is caused by using these functions.
>

When you use TerminateThread to interrupt an existing thread, you must also
close the corresponding handle with CloseHandle() ! if you do not close the
thread handle, the global memory used by your application may increase
dramatically !

Best regards

--

-----------------------------------------------------------
Didier CASSEREAU
Laboratoire Ondes et Acoustique
Universite Paris VII, CNRS URA 1503
10 rue Vauquelin, 75231 PARIS Cedex 05, FRANCE
Tel: +33 (0)1.40.79.44.69
Fax: +33 (0)1.40.79.44.68
E-mail: Didier.C...@loa.espci.fr / cas...@ccr.jussieu.fr
http://www.loa.espci.fr

Robert Scott

unread,
Oct 21, 1999, 3:00:00 AM10/21/99
to
On Thu, 21 Oct 1999 07:04:04 +0200, Didier CASSEREAU
<Didier.C...@espci.fr> wrote:

>
>
>"José Luis Lombana Aramendía" wrote:
>
>> Hello,
>>
>> I´m developing an application that checks the state of a certain
>> number of threads. Sometimes any or all threads fails, and then
>> is necessary to kill them; for doing this, I use TerminateThread.
>> After this I restart each thread, using _beginthreadex. This works,
>> but I have virtual and physical losses; and I suspect that the problem
>> is caused by using these functions.
>>
>
>When you use TerminateThread to interrupt an existing thread, you must also
>close the corresponding handle with CloseHandle() ! if you do not close the
>thread handle, the global memory used by your application may increase
>dramatically !

The leak is much worse than this. The entire stack of the terminated
thread is left allocated. The best solution is to find out why your
treads are failing and recode them so they always will exit
gracefully when the main thread wants them to.


Robert Scott
Ann Arbor, Michigan (email: rscott (at) wwnet (dot) net )
(My automatic return address is intentionally invalid to foil spammers.)

0 new messages