Artifacts Associated With Ticket 597936ffffffffffffffffffffffffffffffffff
Ticket change [b07ac7d139] (rid 97987) by msofer on 2002-08-20 20:39:58:
- assignee initialized to: "msofer"
- cmimetype initialized to: "text/plain"
- comment initialized to:
The following script runs forever. With the new Tcl_Obj allocator (USE_THREAD_ALLOC) its memory grows slowly but steadily; all seems fine with the standard allocator. lappend auto_path /CVS/thread/unix package require Thread proc spawn {} { global i after 10 spawn thread::create "puts [incr i]" flush stdout } set i 0 spawn vwait forever - foundin initialized to: "None"
- priority initialized to: "9 Immediate"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "msofer"
- subsystem initialized to: "41. Memory Allocation"
- title initialized to: "leak in new thread allocator"
- type initialized to: "Bug"
Ticket change [bca1ad062c] (rid 101785) by msofer on 2002-08-22 21:10:18:
- icomment:
Logged In: YES user_id=148712 Note that this has nothing to do with [after], the following shows the same behaviour: lappend auto_path /CVS/thread/unix package require Thread set i 0 while 1 { thread::create "puts [incr i]" } - login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
- icomment:
Ticket change [6fd80f387c] (rid 100380) by andreas_kupries on 2002-08-22 21:47:56:
- icomment:
Logged In: YES user_id=75003 Hm. Could it be that the pool of objects associated with a thread is not freed after a thread is done. Or maybe they are just shuffled around into the global pool. In both situations we would have an ever-growing list of free objects. Either as true leak, or simply because we keep creating thread-object-pools but never using the allocated objects.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [36a4d24dfd] (rid 107144) by msofer on 2002-08-22 22:03:02:
- icomment:
Logged In: YES user_id=148712 Mmhh ... seems to be related to tclsh not cleaning up properly on exit - in particular, the encoding stuff. I could detect where the leak is with valgrind; the leaked mem was created from ==7357== at 0x400467C4: malloc (vg_clientfuncs.c:100) ==7357== by 0x805D430: TclThreadAllocObj (in /CVS/tcl_SF_clean/unix/tclsh) ==7357== by 0x8055F87: Tcl_NewObj (in /CVS/tcl_SF_clean/unix/tclsh) ==7357== by 0x80657C8: TclpInitLibraryPath (in /CVS/tcl_SF_clean/unix/tclsh) ==7357== by 0x8089693: TclFindEncodings (in /CVS/tcl_SF_clean/unix/tclsh) ==7357== by 0x8087C28: Tcl_FindExecutable (in /CVS/tcl_SF_clean/unix/tclsh) ==7357== by 0x805508A: Tcl_Main (in /CVS/tcl_SF_clean/unix/tclsh) ==7357== by 0x8054EE7: main (in /CVS/tcl_SF_clean/unix/tclsh) ==7357== by 0x4029E627: __libc_start_main (../sysdeps/generic/libc-start.c:129) ==7357== by 0x8054DE1: strcpy@@GLIBC_2.0 (in /CVS/tcl_SF_clean/unix/tclsh)
- login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
- icomment:
Ticket change [e350485c22] (rid 87775) by msofer on 2002-08-22 22:12:25:
- icomment:
Logged In: YES user_id=148712 Aarghh ... looking at the wrong place, disregard previous comment! Leak is from ==7385== at 0x400467C4: malloc (vg_clientfuncs.c:100) ==7385== by 0x805D430: TclThreadAllocObj (in /CVS/tcl_SF_clean/unix/tclsh) ==7385== by 0x8055F87: Tcl_NewObj (in /CVS/tcl_SF_clean/unix/tclsh) ==7385== by 0x8066EDB: Tcl_CreateInterp (in /CVS/tcl_SF_clean/unix/tclsh) ==7385== by 0x4023F0D8: NewThread (in /CVS/thread/unix/libthread2.4.so) ==7385== by 0x40250166: thread_wrapper (vg_libpthread.c:521) ==7385== by 0x4004B7E0: do__apply_in_new_thread_bogusRA (vg_scheduler.c:2023)
- login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
- icomment:
Ticket change [0df9f67f28] (rid 94528) by andreas_kupries on 2002-08-22 22:16:55:
- icomment:
Logged In: YES user_id=75003 This does seem to match my explanation. Objects allocated during construction of the thread are not freed when tearing it down. Possibly just moved over to the global pool.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [cbf474e191] (rid 95607) by msofer on 2002-08-23 19:35:50:
- icomment:
Logged In: YES user_id=148712 With an fprintf here and an fprintf there, eeah eeah oh... All objects should be moved to the global pool by the TclFreeAllocCache exit handler. However, some objects in each thread (in this example, 286 of them) are not being moved over at thread exit, and are leaked. Apparently TclFreeAllocCache is being called before all objects have been decrRefCount'ed out of existence? From 'man pthread_key_create': "The order in which destructor functions are called at thread termination time is unspecified."
- login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
- icomment:
Ticket change [3393795718] (rid 106619) by vasiljevic on 2002-08-24 05:01:29:
- icomment:
Logged In: YES user_id=95086 Simple. Here's the CVS diff: Index: tclObj.c =================================================================== RCS file: /cvsroot/tcl/tcl/generic/tclObj.c,v retrieving revision 1.39 diff -r1.39 tclObj.c 686c686,688 < --- > #ifdef USE_THREAD_ALLOC > TclThreadFreeObj(objPtr); > #else 698a701 > #endif /* USE_THREAD_ALLOC */ It was a simple matter of not calling the right release. So the memory was allocated with the new and released with the old allocator. This is not a thread issue per-se. Cheers Zoran
- login: "vasiljevic"
- mimetype: "text/plain"
- username: "vasiljevic"
- icomment:
Ticket change [d3bd6280bc] (rid 123335) by vasiljevic on 2002-08-24 05:14:10:
- icomment:
Logged In: YES user_id=95086 Unfortunately, this was not the only issue. Apparently, there are some others, which I'm still looking at. So, stay tuned.
- login: "vasiljevic"
- mimetype: "text/plain"
- username: "vasiljevic"
- icomment:
Ticket change [54e1d77862] (rid 94030) by msofer on 2002-08-24 07:29:52:
- icomment:
Logged In: YES user_id=148712 I think it is the Tcl_DecrRefCount macro in tcl.h (line 791). If we want to keep binary compatibility, we shouldn't modify that macro - rather redefine TclFreeObj() to do the right thing.
- login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
- icomment:
Ticket change [dde546dafe] (rid 114759) by msofer on 2002-08-24 08:31:27:
- closedate changed to: "2002-08-24T01:31:27"
- closer changed to: "msofer"
- icomment:
Logged In: YES user_id=148712 OK, that was it. Zoran's patch was unlocking a mutex which hadn't been locked - fixed #ifdef's and committed to HEAD.
- login: "msofer"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- username: "msofer"
Ticket change [c22553dae2] (rid 111443) by msofer on 2002-08-24 21:16:50:
- assignee changed to: "vasiljevic"
- icomment:
Logged In: YES user_id=148712 Oops ... I should get more sleep indeed! Zoran's patch did solve the issue, I had just applied it wrongly ... So: reopening, whatever else Zoran saw is not the error I was getting from his patch. Sorry Zoran :(
- login: "msofer"
- mimetype: "text/plain"
- resolution changed to: "Works For Me"
- status changed to: "Open"
- username: "msofer"
Ticket change [17364aafbb] (rid 122451) by vasiljevic on 2002-08-29 16:38:05:
- closedate changed to: "2002-08-29T09:38:05"
- closer changed to: "vasiljevic"
- icomment:
Logged In: YES user_id=95086 After careful (memdebug/purify) testing it seems that this one can be closed safely.
- login: "vasiljevic"
- mimetype: "text/plain"
- status changed to: "Closed"
- username: "vasiljevic"