Itcl - the [incr Tcl] extension

View Ticket
Login
Ticket Hash: 8e632ce049d71998948e465c7749b686812d25d0
Title: Nested eval within method leak memory
Status: Closed Type: Code_Defect
Severity: Critical Priority: Immediate
Subsystem: Resolution: Fixed
Last Modified: 2019-11-26 14:29:33
5.44 years ago
Created: 2019-11-26 09:40:31
5.44 years ago
Version Found In: 4.x
User Comments:
schmitzu added on 2019-11-26 09:40:31:
The following script leaks memory:
```
package require Itcl

itcl::class C1 {
   public    proc   factory {}
   public    method mytry {script}
   private   method read1 {}
   private   method read2 {}
}

itcl::body C1::factory {} {
   set obj [uplevel #0 C1 #auto]
   $obj read1
   return $obj
}

itcl::body C1::read1 {} {
   mytry {read2}
}

itcl::body C1::read2 {} {
   mytry {}
}

itcl::body C1::mytry {script} {
   try {uplevel 1 $script}
}

for {set i 0} {$i < 10000000} {incr i} {
   set obj [C1::factory]
   itcl::delete object $obj
}
```

As a hint I can say hat it has to do something with the
nested try calls.

sebres added on 2019-11-26 11:27:12:

This has nothing with try, but more with nested code evaluation every kind.

Simplest code leaking memory more aggressively looks like:

itcl::class C1 {
  method myeval {script} { eval $script }
  method read {} { myeval {} }
}
proc factory {} {
  set obj [C1 #auto]
  $obj myeval [list $obj read]
  itcl::delete object $obj
}
timerate { factory } 5000

Evaluation with empty body of the read method doesn't show the leak (so it is indeed nested evaluation only).
Also repeat of myeval inside factory (by the single object) doesn't produce a leak en masse (looks like the leaking reference is bound on object reference).

The error looks very old, because also pretty reproducible with Itcl 4.1.2 and even 4.0.3.
Itcl 3.x seems to be not affected.


sebres added on 2019-11-26 13:47:20:

Fixed now in branch bug-8e632ce049 and merged in trunk.


schmitzu added on 2019-11-26 14:29:33:
I can confirm that it is fixed in trunk now.
Thank you very much!