Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 3b6091586af54fbe26bfdad9b83b487a3d7fbdb6
Ticket: 219597ffffffffffffffffffffffffffffffffff
Memory leak with info exists and arrays
User & Date: msp on 2000-10-28 01:53:46
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    I've noticed some strange memory leaks using
    info exists on arrays.The leak is also present in 8.3.1.
    I'm running Tcl on Linux. The below scripts demonstrate
    the memory leak.
    
    # this leaks big time
    
    proc main {argv} {
        expr {srand([clock clicks])}
    
        for {set i 0} {$i < 1000} {incr i} {
    set n1 [expr {int(rand() * 1000)}]
    set n2 [expr {int(rand() * 1000)}]
    set x($n1,$n2) 0
        }
    
        while {1} {
    set n1 [expr {int(rand() * 1000)}]
    set n2 [expr {int(rand() * 1000)}]
    
    if {[info exists x($n1,$n2)]} {
        incr x($n1,$n2)
    }
        }
    }
    
    # no leak
    
    proc main2 {argv} {
        expr {srand([clock clicks])}
    
        for {set i 0} {$i < 1000} {incr i} {
    set n1 [expr {int(rand() * 1000)}]
    set n2 [expr {int(rand() * 1000)}]
    set x($n1,$n2) 0
        }
    
        while {1} {
    set n1 [expr {int(rand() * 1000)}]
    set n2 [expr {int(rand() * 1000)}]
    
    catch {
        incr x($n1,$n2)
    }
        }
    }
    
    # no leak
    
    proc main3 {argv} {
        expr {srand([clock clicks])}
    
        for {set i 0} {$i < 1000} {incr i} {
    set n1 [expr {int(rand() * 1000)}]
    set x($n1) 0
        }
    
        while {1} {
    set n1 [expr {int(rand() * 1000)}]
    
    if {[info exists x($n1)]} {
        incr x($n1)
    }
        }
    }
    
  4. foundin changed to: "obsolete: 8.4a1"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "msp"
  9. subsystem changed to: "07. Variables"
  10. title changed to: "Memory leak with info exists and arrays"
  11. type changed to: "Bug"