Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

finding memory hogs in Tcl/Itcl/tix

58 views
Skip to first unread message

Ralf Fassel

unread,
Jul 11, 2015, 7:08:57 AM7/11/15
to
tcl 8.5.18
itcl 3.4

I'm currently trying to mail down a growing memory problem in my
application. valgrind has not revealed anything conspicious, all
reported losses are either ok (allocated but intentionally not freed),
or just a minor number of bytes.

My app grows some 100MB in one day and eventually crashes, so I suspect
that probably somewhere there might be a TCL variable or list becoming
bigger and bigger.

Is there a way to ask TCL to "list the size of all variables you know of
in all namespaces, plain TCL, itcl and whatever"?

I'd start with

proc getlen_var {var} {
if {[catch {string length [set $var]} len]} {
# it might be an array
puts "$var\t[array size $var]\tARRAY"
foreach {key value} [array get $var] {
puts "${var}($key)\t[string length $value]\tVAR"
}
} else {
puts "$var\t$len\tVAR"
}
}

proc getlen_globals {} {
foreach var [info globals] {
getlen_var ::$var
}
}

proc getlen_namespace {ns} {
if {$ns ne ""} {
foreach cns [namespace children $ns] {
# recurse
getlen_namespace $cns
}
# current ns
foreach var [info vars ${ns}::*] {
getlen_var $var
}
# itcl?
if {![catch {itcl_info objects -class $ns} objs]} {
foreach obj $objs {
getlen_itcl_obj $obj
}
}
}
}

proc getlen_itcl_obj obj {
foreach var [$obj info variable] {
set value [$obj info variable $var -value]
if {$value ne "<undefined>"} {
# plain variable
puts "$var\t[string length $value]\tVAR"
} else {
puts "$var\t???\tARRAY"
}
}
}


In getlen_itcl_obj(), I'm having trouble getting at the arrays in itcl
objects. How to inspect them from the outside?

TNX
R'

Ralf Fassel

unread,
Jul 20, 2015, 5:23:47 AM7/20/15
to
* Ralf Fassel <ral...@gmx.de>
| tcl 8.5.18
| itcl 3.4
>
| Is there a way to ask TCL to "list the size of all variables you know of
| in all namespaces, plain TCL, itcl and whatever"?

Answering my own post: a first step would also be compiling TCL with
--enable-symols==mem
to get the built-in memory debugging support, which provides an overall
picture of TCL's memory usage.

R'
0 new messages