Deletes a class object OR a class definition.
See itcl::class for simple class examples. itcl::delete releases the memory held in the instance.
Deletion automatically calls the destructor method, where any subsidiary tidying up is performed.
package require Itcl itcl::class helloworld { variable next "" ;# to form a linked list of helloworlds constructor {} {puts "helloworld object $this has been created"} destructor { puts "helloworld object $this deleted" if {$next!=""} { itcl::delete object $next } } method addtolist {newhw} { if {$next==""} { set next $newhw } else { $next addtolist $newhw } } method list {} { puts "$this has next $next" if {$next!=""} { $next list } } } helloworld h1 helloworld h2 helloworld h3 helloworld h4 h1 addtolist h2 h1 addtolist h3 h1 addtolist h4 # this will print the entire list from h1 to h4. h1 list # this deletes h1 then h2 (which deletes h3, which deletes h4) itcl::delete object h1
The last statement deletes all objects as they are in the list. Then h1 h2 h3 and h4 will be undefined, beware. The output from the fragment above is:
helloworld object ::h1 has been created helloworld object ::h2 has been created helloworld object ::h3 has been created helloworld object ::h4 has been created ::h1 has next h2 ::h2 has next h3 ::h3 has next h4 ::h4 has next helloworld object ::h1 deleted helloworld object ::h2 deleted helloworld object ::h3 deleted helloworld object ::h4 deleted
The command
itcl::delete class helloworld
will prevent any further helloworld objects being created, and deletes all instances of helloworld object.
helloworld h1 helloworld h2 itcl::delete class helloworld
will delete h1, h2 and the class definition, so you will see:
>> helloworld object ::h2 deleted >> helloworld object ::h1 deleted (bin) 19 % helloworld h4 invalid command name "helloworld"