Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2012-11-20
03:22 • Closed ticket [1521416fff]: thread::release on win32 does not release all memory... artifact: 96e95dabfc user: mistachkin
03:20 • Ticket [1521416fff]: 4 changes artifact: 54810d341d user: mistachkin
01:59 • Ticket [1521416fff]: 4 changes artifact: a861997533 user: dgp
2012-11-14
03:56 • Ticket [1521416fff]: 1 change artifact: 25453101a7 user: dgp
2012-04-24
22:37 • Open ticket [1521416fff]. artifact: 5e9b3febf3 user: dgp
22:23 • Ticket [1521416fff]: 4 changes artifact: 593672913e user: sebres
21:43 • Pending ticket [1521416fff]. artifact: c3567d67b0 user: dgp
2010-09-29
03:07 • Ticket [1521416fff]: 4 changes artifact: 5da43b3e3c user: vasiljevic
2007-06-30
22:37 • Ticket [1521416fff]: 5 changes artifact: cad88ddea7 user: vasiljevic
2006-08-06
16:02 • Ticket [1521416fff]: 4 changes artifact: a597257561 user: vasiljevic
2006-07-12
19:53 • New ticket [1521416fff]. artifact: fab8bbf2c3 user: nobody

thread::release on win32 does not release all memory

Closed / Out of Date1521416fffffffffffffffffffffffffffffffffCreated 20 years agoUpdated 14 years ago
Descriptionplain2006-07-12 19:53:10
The original usenet posting - 
 All 5 messages in topic - view as tree

From:[email protected] - view profile
Date:Tues, Jul 11 2006 11:01 am
Email: [email protected]
Groups: comp.lang.tcl
Not yet rated
Rating: 
show options

Reply | Reply to Author | Forward | Print | Individual
Message | Show original | Report Abuse | Find messages
by this author

I am running tcl 8.4 on Windows XP Pro 2002, SP2.
The simple script below fails on thread::create right
under 12,000
iterations.

Attempts to create any more threads fail in the same
shell once a call
to
thread::create fails.
Restarting tclsh and rerunning seems to work fine
within the limits
mentioned
above.

Would anyone know the reason this would fail?

---------------
tclsh
package require Thread
set i 1
while { 1 } {
  set id [thread::create]
  thread::release $id
  puts -nonewline " $i "
  flush stdout
  update
  incr i

} 




From:David Gravereaux - view profile
Date:Wed, Jul 12 2006 12:17 pm
Email: David Gravereaux <[email protected]>
Groups: comp.lang.tcl
Not yet rated
Rating: 
show options

Reply | Reply to Author | Forward | Print | Individual
Message | Show original | Report Abuse | Find messages
by this author

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

joe,

I ran your script this time and I see what's going on :)

The Tclsh process runs out of virtual memory space! 
Not committed
memory..  True VM allocations.  I even tried the old
fashioned way with
thread::wait and thread::unwind that I personally know
for a fact do not
leak handles..  The issue is not a handle leak.  The
issue is not
committed memory (apparently), but it appears that for
each thread
created, a slice of VM is given to it permanently and
that slice isn't
recouped (though it appears to have been uncommitted).

Joe, insert your script as a new bug.  There's
something going on that's
a bit deeper than proper handle management.

the Old way (that has the same behavior):

package require Thread
set i 1
while { 1 } {
  set id [thread::create {thread::wait}]
  thread::send -async $id {thread::unwind}
  puts -nonewline " $i "
  flush stdout
  update
  incr i

}
vasiljevicplain2006-08-06 16:02:21
Logged In: YES 
user_id=95086

Hi!

This is I believe the side-effect of the thread memory allocator
which is known to be memory greedy as it was optimized on
speed and not memory usage. I have seen this behaviour on 
all Unices as well, not only Windows. Although it seems that on
Unices is far less visible. I'm able to create and terminate about
30.000 threads and the VM usage increases about 1MB.
vasiljevicplain2007-06-30 22:37:00
Logged In: YES 
user_id=95086
Originator: NO

I will still leave this open but will try to replace
the greedy Tcl memory allocator with just calls
to regular system allocator and see if this helps. 
If yes then we can think of making an alternate 
allocator for Tcl OR even just simple use the 
system-level one as those beasts are more
thread-aware today as they have been 5 year ago.
vasiljevicplain2010-09-29 03:07:50
Perhaps this is a problem related to memory leak in the teardown logic.
I will need to investigate the memory leak problem first.
dgpplain2012-04-24 21:43:30
Testing the trunk (2.6.8) and thread-2-7-branch (2.7b1)
on Linux with the submitted test scripts I see no leaks
with the Tcl trunk.

Would be good for someone to confirm on Windows.
sebresplain2012-04-24 22:23:54
I could also not reproduce it on linux, but in windows.
see also bug 3493120: https://sourceforge.net/tracker/?func=detail&aid=3493120&group_id=10894&atid=110894
Possible the same bug?
Have a linux kernel any "garbage collector" for therminated threads, its shared memory or something else?
dgpplain2012-04-24 22:37:04
ok then
dgp Ticket [1521416fff]: 1 change [History diff]2012-11-14 03:56:41
dgpplain2012-11-20 01:59:26
Joe, did we decide this one is out of date?

That is, the leak problems on Windows are
already fixed?  Thanks for closing this ticket
if you confirm.
mistachkinplain2012-11-20 03:20:57
Used the provided test script on Windows 8 and created 16K threads.  Total memory used by the process was around 2MB.  Therefore, no leak.
mistachkinplain2012-11-20 03:22:02
allow_comments - 1
Log in (anonymous is fine) to add a comment.