Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2007-06-30
21:59 • Closed ticket [1464731fff]: Memory leak in Thread release plus 7 other chang... artifact: d13fad20d2 user: vasiljevic
2006-04-06
00:02 • Ticket [1464731fff]: 4 changes artifact: 4fb6ba3950 user: nobody
2006-04-05
17:30 • Ticket [1464731fff]: 2 changes artifact: 8e25c527e9 user: dkf
07:23 • New ticket [1464731fff]. artifact: 868085e1ae user: nobody

Memory leak in Thread release

Closed / Wont Fix1464731fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 19 years ago
Descriptionplain2006-04-05 07:23:48
Hi,
     It seems there is memory leak in Thread release 
call. I have attched the sample script for 
Theread "create/release". For each thread release 
there was around 65KB of memory leak. More over if I 
provide any package in Thread send call the leak was 
pretty much high(400KB).So please have look into this 
issue and suggest me a solution.

OS : Windows 2000
Thanks,
Karthik
Email:[email protected]
dkf Ticket [1464731fff]: 2 changes [History diff]2006-04-05 17:30:57
nobodyplain2006-04-06 00:02:10
Logged In: NO 

I have written a sample script in which I have provided 
tcltest package in thread send call. Each thread consumes 
800KB of memory , but while release only 75KB of memory is 
released.Please find the sample script below.

package require Thread
array set ::NewThread {}
set ::mcount 10

after 4000
# Program Mem-Usage here is 2260K
for  {set count 1} {$count < $::mcount} {incr count} {

   set ::NewThread($count) [thread::create -joinable { 
thread::wait }]
   puts "Created Thread NewThread($count):  $::NewThread
($count)"

   for  {set cnt 1} {$cnt < 100 } {incr cnt} {
      thread::send $::NewThread($count) {
         package require tcltest
         puts "xxxxxxxxxxxxxxhello worldxxxxxxxxxxxxxxxxxx"
      }
   }
}

after 4000
# Program Mem-Usage here is 9880K
for  {set count 1} {$count < $::mcount} {incr count} {

   thread::release $::NewThread($count)
   puts "Released Thread NewThread($count) : $::NewThread
($count)"
   
   thread::join $::NewThread($count)
   puts "NewThread($count) Thread Terminated"

}

puts "Quiting............"
# Program Mem-Usage here is 9180K
after 4000
vasiljevicplain2007-06-30 21:59:39
Logged In: YES 
user_id=95086
Originator: NO

The problem is that you are creating threads with "-joinable" 
but you never join them. Instead you "thread::release" them.
Either skip "-joinable" or use "thread::join" to collect the 
exiting thread.

I agree that it is not clear when to call what and this has something
to do with the history. I will try to simplify the API and remove 
some commands out of it to make it more easier to use. Yet, I will
have to wait for 3.0 to do that.
Log in (anonymous is fine) to add a comment.