When sourcing several times a tcl script using itcl, there may be a problem because classes we want to create already exists.
Here is a recipe to allow source and source again of such scripts; the point is that
# # tcl 8.4.1 / itcl3.2 (tested on windows xp) # # how to properly delete objects and classes in itcl # # delete objects and classes foreach objid [find objects] { if { [find objects $objid] != "" } { delete object $objid } } foreach classid [find classes] { # avoid to delete already deleted classes if { [find classes $classid] != "" } { delete class $classid } }
Note that classes containing object references of other classes must delete these references, but always with a check "exists ? okay, delete"
public variable childrenlist; # containing a list of children objects destructor { foreach child $childrenlist { if { [find objects $child] != "" } { delete object $child } } }
See also incr Tcl