John Jester <
kuulg...@gmail.com> writes:
> There seems to be a memory leak with the clock format command. I've
> tested this in freewrap 6.74 on Windows and tclsh 8.6 on Linux with
> the same result.
>
> Using this code:
>
> for { set i 0 } { $i < 1000 } { incr i } { clock format 0 -format [expr rand()] }
>
> I see an increase in memory of about ~2 MB. Increasing the limit from
> 1,000 to 10,000 yields a memory increase of ~20 MB, so it seems linear
> at about 2 kB leaked per iteration. Same for 100,0000, with ~200 MB
> increase.
From what I see this is not lost memory in the sense of a true memory
link - true here means the application has allocated memory but lost any
reference to that. Valgrind doesn't show anything new.
But yes, this is a way to make a Tcl process go out of any bound with
respect to maximum resident memory size.
It's the always changed -format option, which makes this. See this
script:
proc doit {nr} {
for { set i 0 } { $i < $nr } { incr i } {
clock format 0 -format $i
}
}
doit $argv
Called with the arugments 1000, 10000, 20000 etc shows an alway linar
growing maximum resident set size of the process during its lifetime.
This script
proc doit {nr} {
for { set i 0 } { $i < $nr } { incr i } {
clock format $i -format 0
}
}
doit $argv
called with the arugments 1000, 10000, 20000 etc have all the same (low)
maximum resident set size of the process during its lifetime (as
expected). And run more than a magnitude faster as above.
There's some caching of processing of the -format specification in
place, or something like this.
The assumption (and probably not an immediately unreasonable) here seems
to be that you have only at max a few handful different formats but you
use any of this formats potentially again and again for different
values. And that should be fast. Think: Timestamp in an ever growing log
file.
Or so it looks at least from outside. I haven't looked so far on the
implementation.
rolf