Artifacts Associated With Ticket 2874678
Ticket change [66a7c28320] (rid 102751) by wastl-nagel on 2009-10-08 12:35:15:
- assignee initialized to: "dkf"
- cmimetype initialized to: "text/plain"
- comment initialized to:
If a dict is created and filled via "dict incr" with a bigger set of keys it seems to leak. If the dict is destroyed (unset or overwritten) a lot of memory still keeps allocated. The following code consumes approx. 500MB memory on my machine (Linux, 64-bit): set chars {a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9} for {set i 0} {$i < 1000} {incr i} { append prefix [lindex $chars [expr int([tcl::mathfunc::rand]*62)]] set dictionary [dict create] foreach char $chars { foreach c $chars { dict incr dictionary $prefix$char$c $i } } } I've tested Tcl 8.5.2 (OpenSuSE 11.0, x86_64), 8.5.7, 8.6b1 (both built from source), all three leak, cf. attached valgrind log files for same code but only 100 cycles. For 8.5.2 TclBN_mp_init_size according to valgrind seems to be reason. % uname -mrvs Linux 2.6.25.20-0.5-default #1 SMP 2009-08-14 01:48:11 +0200 x86_64 - foundin initialized to: "obsolete: 8.5.7"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "wastl-nagel"
- subsystem initialized to: "15. Dict Object"
- title initialized to: "dict incr leaks"
- type initialized to: "Bug"
Add attachment "valgrind_tcl_dict.zip" [52400f243b] (rid 126283) by wastl-nagel on 2009-10-08 19:35:19.
Ticket change [e9f7279d17] (rid 104897) by wastl-nagel on 2009-10-08 19:35:20:
- icomment:
File Added - 345735: valgrind_tcl_dict.zip
- login: "wastl-nagel"
- mimetype: "text/plain"
- username: "wastl-nagel"
- icomment:
Ticket change [20a6be83c4] (rid 130462) by wastl-nagel on 2009-10-08 20:26:03:
- icomment:
May the patch below fix the problem? --- ./generic/tclDictObj.c~ 2009-01-06 17:07:17.000000000 +0100 +++ ./generic/tclDictObj.c 2009-10-08 15:00:29.000000000 +0200 @@ -2148,6 +2148,7 @@ mp_int increment; code = Tcl_GetBignumFromObj(interp, objv[3], &increment); + mp_clear(&increment); if (code != TCL_OK) { Tcl_AddErrorInfo(interp, "\n (reading increment)"); } else { - login: "wastl-nagel"
- mimetype: "text/plain"
- username: "wastl-nagel"
- icomment:
Ticket change [c3578bf654] (rid 111642) by dkf on 2009-10-08 21:10:09:
- priority changed to: "9 Immediate"
Ticket change [2b27f14a1b] (rid 118687) by dkf on 2009-10-08 21:21:09:
- icomment:
Leaks 8 words per *interpreted* [dict incr] that creates a dictionary entry.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [228bd34531] (rid 130766) by dkf on 2009-10-08 21:22:24:
- icomment:
And requires an explicit increment to do so.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [b831f19bae] (rid 128932) by dkf on 2009-10-08 21:24:57:
- icomment:
The following test seems to be exact: test dict-19.3 {dict: testing for leaks - Bug 2874678} -setup { proc memtest script { set end [lindex [split [memory info] \n] 3 3] for {set i 0} {$i < 5} {incr i} { uplevel 1 $script set tmp $end set end [lindex [split [memory info] \n] 3 3] } expr {$end - $tmp} } } -constraints memory -body { set d aDictVar; # Force interpreted [dict incr] memtest { dict incr $d aKey 0 unset $d } } -cleanup { unset d rename memtest {} } -result 0 - login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [6726aadc0a] (rid 102854) by dkf on 2009-10-08 21:44:11:
- icomment:
Fixed in HEAD and 8.5 (the patch was slightly wrong, but helped narrow down what needed to be done a lot; thanks!)
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [a724b11707] (rid 98732) by dkf on 2009-10-08 21:44:12:
- closedate changed to: "2009-10-08T14:44:12"
- closer changed to: "dkf"
- icomment:
allow_comments - 1
- login: "dkf"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- username: "dkf"