Skip to content
Tcl Source Code History Of Ticket 1869989
Login

History Of Ticket 1869989

Artifacts Associated With Ticket 1869989

  1. Ticket change [5f1e468ee8] (rid 115760) by melbardis on 2008-01-12 16:45:13:

    1. assignee initialized to: "hobbs"
    2. cmimetype initialized to: "text/plain"
    3. 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...
      
      
      
    4. foundin initialized to: "obsolete: 8.5.0"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "melbardis"
    10. subsystem initialized to: "41. Memory Allocation"
    11. title initialized to: "memory leak when using expr"
    12. type initialized to: "Bug"
  2. Ticket change [fe83ca9ba9] (rid 108605) by nobody on 2008-01-12 23:51:26:

    1. 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!
      
      
      
    2. login: "[email protected]"
    3. mimetype: "text/plain"
    4. username: "[email protected]"
  3. Ticket change [e610c0f50e] (rid 104234) by dgp on 2008-01-13 01:30:41:

    1. assignee changed to: "dgp"
    2. subsystem changed to: "47. Bytecode Compiler"
  4. Ticket change [b87e03b619] (rid 128975) by dgp on 2008-01-15 13:31:01:

    1. 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.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  5. Ticket change [1722512d3e] (rid 124832) by dgp on 2008-01-15 13:31:02:

    1. closedate changed to: "2008-01-15T06:31:02"
    2. closer changed to: "dgp"
    3. resolution changed to: "Works For Me"
    4. status changed to: "Pending"
  6. Ticket change [7825de2a95] (rid 89906) by dgp on 2008-01-15 13:51:05:

    1. 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.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  7. Ticket change [1f3dbe2b20] (rid 91117) by melbardis on 2008-01-15 22:51:14:

    1. 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
      
      
    2. login: "melbardis"
    3. mimetype: "text/plain"
    4. status changed to: "Open"
    5. username: "melbardis"
  8. Ticket change [2e028452f9] (rid 119151) by dgp on 2008-01-16 00:00:11:

    1. 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.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  9. Ticket change [b788f4cd03] (rid 125616) by melbardis on 2008-01-16 00:04:54:

    1. closedate changed to: "2008-01-15T17:04:54"
    2. closer changed to: "melbardis"
    3. 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
      
      
      
    4. login: "melbardis"
    5. mimetype: "text/plain"
    6. status changed to: "Closed"
    7. username: "melbardis"
  10. Ticket change [b2f9b30b7e] (rid 98435) by dgp on 2008-01-16 02:41:56:

    1. 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.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. priority changed to: "9 Immediate"
    5. resolution changed to: "Remind"
    6. status changed to: "Open"
    7. username: "dgp"
  11. Ticket change [dd6d9ae5f1] (rid 114668) by dgp on 2008-01-16 02:53:45:

    1. 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.
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  12. Add attachment "1869989.patch" [6f88f99406] (rid 100329) by dgp on 2008-01-17 02:11:23.

  13. Ticket change [c9f0822d56] (rid 122375) by dgp on 2008-01-17 02:11:23:

    1. assignee changed to: "msofer"
    2. 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
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. username: "dgp"
  14. Ticket change [54177c963b] (rid 93880) by msofer on 2008-01-17 02:49:21:

    1. closedate changed to: "2008-01-16T19:49:21"
    2. closer changed to: "msofer"
    3. icomment:
      Logged In: YES 
      user_id=148712
      Originator: NO
      
      Patch reviewed, approved, committed.
      
      
    4. login: "msofer"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "msofer"