Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2001-09-11
08:18 • Closed ticket [229969ffff]: Memory Leak TCL 8.3.0 in TclAlloc plus 7 other c... artifact: c7f10998f4 user: hobbs
2001-08-07
07:29 • Ticket [229969ffff]: 1 change artifact: 569e8ce493 user: hobbs
2001-01-31
17:48 • Ticket [229969ffff]: 1 change artifact: 69dd6ae4a3 user: dkf
2001-01-25
17:03 • Ticket [229969ffff]: 4 changes artifact: 03b6d6f573 user: dkf
17:03 • Ticket [229969ffff]: 1 change artifact: d3210ff228 user: dkf
2001-01-24
21:36 • New ticket [229969ffff]. artifact: af970e2811 user: nobody

Memory Leak TCL 8.3.0 in TclAlloc

Closed / Invalid229969ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 25 years ago
Descriptionplain2001-01-24 21:36:26
I am creating a interpreter in a C++ program using the call
Tcl_CreateInterp  after that I use Tcl_SetVar to define variable values and then call Tcl_EvalFile to evaluate a script . The code that is running the interpreter is running in its own thread and I use Tcl_GetVar and Tcl_SetVar to communicate with the interpreter from another thread.  All works great but when I delete the interpeter with Tcl_DeleteInterp I find a memory leak of about 10 k due to Tcl_Alloc (using Solaris Workshop Leak Check).  According to My latest TCL/TK book (Welch) calling Tcl_DeleteInterp only marks the interpreter as deleteable and only deletes if Tcl_Release is called as Many Times as Tcl_Preserve.  I modified the Tcl Code to emit a message to stdout when Tcl_Preserve is called. At no time is the message seen unless I specifically call it in my C++ program. I have called Tcl_UnsetVar on all my global variable prior to deletion and it has no effect.  All my variables are set with the option TCL_GLOBAL_ONLY flag. 
1 ) if the call Tcl_DeleteInterp marks the interpreter as deletable and then returns how is the deletion code ever going to run ?
2) If Tcl_DeleteInterp does indeed try to remove all memory
before returning then you have a memory leak problem.
3) If you don't think you have a memory leak problem then given the information above how do I free the variables I Set and Get.  What concerns me is that Tcl reassigns the memory that a variable possesses every time it is set. Do I have to free that memory first before setting (i.e 
char * data = Tcl_GetVar(interp,"data",TCL_GLOBAL_ONLY);
Tcl_Free(data);
?
dkf Ticket [229969ffff]: 1 change [History diff]2001-01-25 17:03:21
dkfplain2001-01-25 17:03:22
Tcl deletes the interpreter when the final matching call to Tcl_Release (matching the calls performed to Tcl_Preserve) is called.  In normal situations, this happens as the stack is unwound in the normal course of things - once an interpreter is deleted, no new commands can be called on it, so unwinding depends entirely on currently running code.

Is there any reason you're not using the Tcl_Obj-based variable access functions?  If nothing else, I understand how they manage memory allocation and free-ing better than with the string-based functions...  :^)
dkf Ticket [229969ffff]: 1 change [History diff]2001-01-31 17:48:10
hobbs Ticket [229969ffff]: 1 change [History diff]2001-08-07 07:29:57
hobbsplain2001-09-11 08:18:54
Logged In: YES 
user_id=72656

You may be getting confused that Tcl_Finalize isn't being 
called.  The Tcl_Obj allocator can sometimes trick leak 
checkers, because Tcl block allocates objects that are kept 
through the lifetime of Tcl (until Tcl_Finalize is 
called).  Certain objects are life outside the realm of a 
single interpreter, and could thus still be alive.  Does 
this really increase by the same amount over multiple 
iterations of the Create/Delete cycle?
Log in (anonymous is fine) to add a comment.