Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2007-06-30
21:02 • Closed ticket [1589794fff]: Memory leaks with TCL_THREADS plus 7 other chang... artifact: 5b948c5778 user: vasiljevic
2007-01-22
16:21 • Ticket [1589794fff]: 4 changes artifact: 87a300ba67 user: celine_thales
16:21 • Add attachment TclEvent_c.txt to ticket [1589794fff] artifact: 181c1d7ed1 user: celine_thales
15:43 • Ticket [1589794fff] Memory leaks with TCL_THREADS status still Open with 4 o... artifact: 4ca42f3a1f user: vasiljevic
15:30 • Ticket [1589794fff]: 4 changes artifact: f63d739520 user: celine_thales
2007-01-20
01:39 • Ticket [1589794fff]: 4 changes artifact: 046775d83a user: vasiljevic
2006-11-03
17:52 • Ticket [1589794fff]: 1 change artifact: d9b2d8a0bf user: dkf
16:28 • Ticket [1589794fff]: 4 changes artifact: b086611272 user: celine_thales
16:28 • Add attachment LogTCL_MEM_DEBUG_thread.txt to ticket [1589794fffffffff|... artifact: 871636c303 user: celine_thales
09:28 • New ticket [1589794fff] Memory leaks with TCL_THREADS. artifact: 636e8c0ee0 user: celine_thales

Memory leaks with TCL_THREADS

Closed / Wont Fix1589794fffffffffffffffffffffffffffffffffCreated 20 years agoUpdated 19 years ago
Descriptionplain2006-11-03 09:28:21
Hello,

I use tcl 8.3.4 on Win XP, and build with Visual C++ 6.0.
In need to use Tcl with thread implementation, and I
add TCL_THREADS compile option in settings of Tcl
project and calling project. Then I saw a lot of memory
leaks that appeared after call of Tcl_Finalize, at the
end of application in debug. I don't use it in a
console, so I use Tcl_Init, and Tcl_Finalize.

I needed to correct a bug in Tcl_FinalizeNotifier so
that it doesn't crash because pointer was NULL (Bug
#217982).

I added TclThread_Init just after Tcl_Init but don't
know if it's necessary.

I tried also with tcl 8.4.13 and this doesn't change
anything for memory leaks.

I tried to track leaks with TCL_MEM_DEBUG and call of
Tcl_DumpActiveMemory without success.

Is there anything special to do to be in multi
threading after setting TCL_THREADS?

Thank you for answering me because I begin to feel lost!

Celine
celine_thalesplain2006-11-03 16:28:22
File Added - 201253: LogTCL_MEM_DEBUG_thread.txt
dkf Ticket [1589794fff]: 1 change [History diff]2006-11-03 17:52:23
vasiljevicplain2007-01-20 01:39:28
Logged In: YES 
user_id=95086
Originator: NO

You are by no means lost. I'm slow but sure :-)
What you experience might be a problem in Tcl core
that badly handles std channels. I'm loking at that
at this moment.
celine_thalesplain2007-01-22 15:30:23
Logged In: YES 
user_id=1631532
Originator: YES

Hi, 
the solution I found at this moment was to add TclFinalizeThreadData in Tcl_Finalize and I modified the way my threads were called, because I realized that Tcl_Init was not necessary executed in the same calling thread as Tcl_Finalize. I have no more leaks now, but my solution might not be the right one.

Thank you to have taken my problem into account.
vasiljevicplain2007-01-22 15:43:36
Logged In: YES 
user_id=95086
Originator: NO

Can you tell me where exactly (post a code excerpt or a diff) you added 
TclFinalizeThreadData?
celine_thalesplain2007-01-22 16:21:04
File Added - 212462: TclEvent_c.txt

Logged In: YES 
user_id=1631532
Originator: YES

I joined diffTclEvent.jpg
File Added: TclEvent_c.txt
vasiljevicplain2007-06-30 21:02:31
Logged In: YES 
user_id=95086
Originator: NO

Allright. The change you made was helping in 
the case Tcl_Init and Tcl_Finalize are not done
in the same thread. 

Normally Tcl_Init and Tcl_Finalize should be called
from the same thread (the main startup thread)
which is the first thread in your process. So the 
first thread should load and init the Tcl library and
it is this one thread that needs to finalize and unload
the Tcl library. You cannot delegate this to some other
thread.
Yep, this is not a sign of a good design and has
quite a few of side-effects like: you must somehow
terminate all threads using Tcl lib before your main
thread that loaded/inited Tcl lib exists.
But that's the way it is now; changing this would 
require a major library rewrite which is expensive. 
For the time being you should always pay attention
to load and finalize Tcl library in the same (preferably 
startup) thread.

Cheers
Zoran
Log in (anonymous is fine) to add a comment.

Attachments: