[vtkusers] [Newbie] TCL problem: vtk objects persisting in second function call
Kevin Wright
krw at viz-solutions.com
Thu Jan 30 13:23:43 EST 2003
>It seems strange regarding the basic idea that an object instanciated
>inside a function should disappear at function's end! So vtk objects are
>persistent and global, or did I really miss something with TCL (I've
>just started learning).
When you create a new object in Tcl, it creates a new "command" to
implement that object. Until you delete that object, that command name is
taken, and cannot be the name of a new object. Think of the objects
created in Tcl as dynamic memory, not static. It must be freed. So, you
have two options. If, at the end of the function you are done with the
object, you can delete it. If you want it to hang around while you re-call
the function, you're going to have to come up with a unique name:
proc func1 {} {
vtkObject obj
...
obj Delete
}
proc func2 {} {
global objCount
vtkObject obj-$objCount
incr objCount 1
...
}
Hope that helps.
Kevin.
More information about the vtkusers
mailing list