Artifacts Associated With Ticket 1869989
Ticket change [5f1e468ee8] (rid 115760) by melbardis on 2008-01-12 16:45:13:
- assignee initialized to: "hobbs"
- cmimetype initialized to: "text/plain"
- comment initialized to:
using [expr ...] in a loop appears to cause a constant memory leak. it appears to be allocating stuff in TclLiterla... also fairly (very) slow operation! tcl 8.5 / windows xp here is the code i used #----------------------------- set numgen 200000 set delta 1 set start_time 1 for {set i 0} {$i < $numgen} {incr i} { set time [expr $start_time + ($delta * $i) ] } #----------------------------- memory start small, now it is about 48K and is still running! like i said slow... - foundin initialized to: "obsolete: 8.5.0"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "melbardis"
- subsystem initialized to: "41. Memory Allocation"
- title initialized to: "memory leak when using expr"
- type initialized to: "Bug"
Ticket change [fe83ca9ba9] (rid 108605) by nobody on 2008-01-12 23:51:26:
- icomment:
Logged In: NO i modified the test to use the opreator syntax as such: #------------------------------ namespace path {::tcl::mathop ::tcl::mathfunc} set numgen 200000 set delta 1 set start_time 1 for {set i 0} {$i < $numgen} {incr i} { #set time [expr $start_time + ($delta * $i) ] set time [+ $start_time [* $delta $i]] } #---------------------------------- almost instant! - login: "[email protected]"
- mimetype: "text/plain"
- username: "[email protected]"
- icomment:
Ticket change [e610c0f50e] (rid 104234) by dgp on 2008-01-13 01:30:41:
- assignee changed to: "dgp"
- subsystem changed to: "47. Bytecode Compiler"
Ticket change [b87e03b619] (rid 128975) by dgp on 2008-01-15 13:31:01:
- icomment:
Logged In: YES user_id=80530 Originator: NO What is your evidence of a memory leak? Your original script runs in about 3 seconds for me on a linux system. Doesn't seem "very" slow considering you're demanding that it reparse the expression and all numbers 200000 times. Of course bracing the expression will solve that, if it is speed rather than demonstrating a leak which is at issue.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [1722512d3e] (rid 124832) by dgp on 2008-01-15 13:31:02:
- closedate changed to: "2008-01-15T06:31:02"
- closer changed to: "dgp"
- resolution changed to: "Works For Me"
- status changed to: "Pending"
Ticket change [7825de2a95] (rid 89906) by dgp on 2008-01-15 13:51:05:
- icomment:
Logged In: YES user_id=80530 Originator: NO Perhaps you are not seeing an actual leak, but just watching memory consumption grow as the accumulated parses allocate space for all the literal values they see? By the time you are done, the values "1", "2", ... "200000" will all be stored in the literal table. The same thing should happen in 8.4.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [1f3dbe2b20] (rid 91117) by melbardis on 2008-01-15 22:51:14:
- icomment:
Logged In: YES user_id=788816 Originator: YES it was the literal table growing that was of concern. 1) is there an upper limit to number of literals allocated? if not then this would have adverse efects on long running server apps that use this construct. 2) why the difference between [expr ..] and the alternative [+ ...] ? regards eric
- login: "melbardis"
- mimetype: "text/plain"
- status changed to: "Open"
- username: "melbardis"
- icomment:
Ticket change [2e028452f9] (rid 119151) by dgp on 2008-01-16 00:00:11:
- icomment:
Logged In: YES user_id=80530 Originator: NO 1) No limit. Yes, over time a program that creates many literals can grow in memory footprint. This is nothing new. 2) The fundamental reason is that you have failed to brace the expression. This means every evaluation of [expr] is creating an expression string, parsing that expression string (which creates literals), and only then compiling and executing the bytecode. A properly braced expression would parse and compile only one time, and let the changing contents of a variable produce changing expression results when executing the same bytecode again and again. Using [+] is more like a braced expression than an unbraced expression. For this example, they produce (nearly?) the same bytecode. Although there's no bug here, it does raise the general question of literal lifetime which might be worth looking into.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [b788f4cd03] (rid 125616) by melbardis on 2008-01-16 00:04:54:
- closedate changed to: "2008-01-15T17:04:54"
- closer changed to: "melbardis"
- icomment:
Logged In: YES user_id=788816 Originator: YES thanks for the explaination i guess i should of read the documentation a little better :) eric
- login: "melbardis"
- mimetype: "text/plain"
- status changed to: "Closed"
- username: "melbardis"
Ticket change [b2f9b30b7e] (rid 98435) by dgp on 2008-01-16 02:41:56:
- icomment:
Logged In: YES user_id=80530 Originator: NO I was mistaken to assume that literal lifetimes were meant to be permanent. There is in fact a conflict in literal lifetime management for those literals in constant (sub-)expressions. Diagnosis of memory leak was correct after all.
- login: "dgp"
- mimetype: "text/plain"
- priority changed to: "9 Immediate"
- resolution changed to: "Remind"
- status changed to: "Open"
- username: "dgp"
- icomment:
Ticket change [dd6d9ae5f1] (rid 114668) by dgp on 2008-01-16 02:53:45:
- icomment:
Logged In: YES user_id=80530 Originator: NO I would expect the same TclReleaseLiteral flaws to cause this script to leak: while 1 { proc demo {} "set ::var val[incr ::i]" demo } But that doesn't appear to be the case. - login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Add attachment "1869989.patch" [6f88f99406] (rid 100329) by dgp on 2008-01-17 02:11:23.
Ticket change [c9f0822d56] (rid 122375) by dgp on 2008-01-17 02:11:23:
- assignee changed to: "msofer"
- icomment:
File Added - 262488: 1869989.patch Logged In: YES user_id=80530 Originator: NO Here's a patch that removes the unbalanced TclCreateLiteral() calls that caused the memleak. Might be interesting to see if tclbench notices anything significantly different after applying this patch. File Added: 1869989.patch
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
Ticket change [54177c963b] (rid 93880) by msofer on 2008-01-17 02:49:21:
- closedate changed to: "2008-01-16T19:49:21"
- closer changed to: "msofer"
- icomment:
Logged In: YES user_id=148712 Originator: NO Patch reviewed, approved, committed.
- login: "msofer"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- username: "msofer"