Version 0 of Deleting itcl objects

Updated 2003-02-03 11:34:13

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 - when deleting an object, other objects may be deleted by

  its destructor

- when deleting a class, all inherited classes may be deleted too.

Vincent Wartelle

  #
  # tcl 8.3.4 / itcl3.2 / on windows
  # 
  # 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 { parent child } {
      # 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"

  destructor {
      foreach child $childrenclass {
          if { [find objects $child] != "" } {
               delete object $child
          }
      }
  }


   }