Tcl Source Code

Ticket Change Details
Login
Overview

Artifact ID: 35cdd7bbb80237481497890f7ad88dc421d30532
Ticket: 3493120fffffffffffffffffffffffffffffffff
Thread extension, memory leak after thread exit
User & Date: sebres 2014-04-22 13:28:58
Changes

  1. assignee changed to: "aku"
  2. closer changed to: "nobody"
  3. comment changed to:
    Version: 8.5.11 (original and current core-8-5-branch)
    Platform: Windows (linux not yet tested)
    
    After exiting of threads, they leave a memory leak. 
    Consequence of that: we cannot use techniques such as 'idletime' (to release some system resources, for example large tcl codes are no more used, etc, etc.).
    
    After run of following script I have lost 100MB of memory. In fact, nothing will be done here, except threads are created and exited.
    
    Test script:
    
    # for test purposes - to wait for threads exited :
    tsv::set testth count 0
    # this create once a thread pool, and generate jobs :
    proc test {} {
      # create a thread pool if not yet already exists :
      if {![llength [tpool::names]]} {
        tpool::create -minworkers 0 -maxworkers 5 -idletime 1 -initcmd {
          # + 1 thread
          tsv::set testth count [expr {[tsv::get testth count] + 1}]; puts [thread::id]init!!!!!
        } -exitcmd {
          # - 1 thread
          tsv::set testth count [expr {[tsv::get testth count] - 1}]; puts [thread::id]!!!!!exit
        }
      }
     # generate jobs until 5 threads are created :
      while {[tsv::get testth count] < 5} {
        tpool::post -detached -nowait [lindex [tpool::names] 0] {
          puts [thread::id]!!job; tsv::array unset testthcount [thread::id]
        }
        update
      }
    }
    # repeat test 100 times, in addition waiting for the 
    # threads to be finished each iteration :
    time {test; while {[tsv::get testth count]} {after 10};} 100
    
  4. icomment:
    Leak found and fixed within [c251d61424]
    TclpFreeAllocCache (if called with ptr != NULL) has a comment: "Called by us in TclpFinalizeThreadData when a thread exits ..."
    But until now it was really never called.
    After fixing, no byte is lost during test.
    
  5. login: "sebres"
  6. mimetype: "text/plain"
  7. severity changed to: "Minor"
  8. username: "sebres"