SourceForge has been redesigned. Learn more.
Close

#799 there is a memory leak when an empty array is created in a p

obsolete: 8.0p2
closed-fixed
nobody
2
2001-04-16
2000-10-26
Anonymous
No

OriginalBugID: 1727 Bug
Version: 8.0p2
SubmitDate: '1999-04-05'
LastModified: '1999-09-16'
Severity: MED
Status: Released
Submitter: pat
ChangedBy: hobbs
OS: All
OSVersion: NA
Machine: NA
FixedDate: '1999-09-16'
FixedInVersion: 8.2
ClosedDate: '2000-10-25'

Name: Mark Falco
email: falcom@dialogic.com
Support: None
Severity: 3
OperatingSystem: Windows NT
Synopsis: there is a memory leak when an empty array is created in a procedure

ReproducibleScript:
proc abc {} {
array set tmp {}
}

while [expr 1] {
abc
}

#watch the memory usage, it skyrockets

ObservedBehavior:
in normal application this is just a slow memory leak over time

DesiredBehavior:
no memory leak

Patch:
here is a tcl script which I'm using to fix the behavior.

rename array array_tcl

proc array {args} {
if {[llength $args] == 3} {
if {[lindex $args 0] == {set}} {
if {[string trim [lindex $args 2]] == {}} {
#avoid a memory leak in Tcl 8.0, when creating empty arrays
upvar 1 [lindex $args 1] name
if ![info exists name] {
set name() {}
unset name()
}
return
}
}
}
uplevel 1 array_tcl $args
}

8.2 shows no noticable signs of mem leak in this proc.
-- 09/16/1999 hobbs

Discussion

  • Brent B. Welch

    Brent B. Welch - 2000-10-26
    • priority: 5 --> 2
    • status: open --> closed-fixed
     
  • Don Porter

    Don Porter - 2001-04-16
    • labels: 104246 --> 07. Variables