Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#3564 Memory leaks with TCL_THREADS

obsolete: 8.3.4
closed-wont-fix
5
2007-06-30
2006-11-03
celine
No

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

Discussion

  • celine
    celine
    2006-11-03

    Trace log with TCL_MEM_DEBUG and Memory leaks

     
    • assigned_to: nobody --> vasiljevic
     
  • 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
    celine
    2007-01-22

    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.

     
  • 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
    celine
    2007-01-22

    tclEvent.c, function Tcl_Finalize

     
    Attachments
  • celine
    celine
    2007-01-22

    Logged In: YES
    user_id=1631532
    Originator: YES

    I joined diffTclEvent.jpg
    File Added: TclEvent_c.txt

     
  • 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

     
    • status: open --> closed-wont-fix