Re: itcl destructor
- From: "Kemper" <kemperk@xxxxxxxxxxx>
- Date: Tue, 30 Aug 2005 23:14:11 -0700
Ant wrote:
"Antonio Ceballos" <ceballos@xxxxxxx> wrote in message
news:df25sd$21v$1@xxxxxxxxxxxxxxxxxxx
> Hi all,
>
> Is there a way to destruct itclobjects? I have not found it.
>
> Cheers,
> Antonio
>
>
I made a itcl reference counting base class that will release an object when
no reference is left to the object. the reference is automaticaly added to
the object in the constructor. If you have a variables refering tot he
object then you can incr the reference count. calling relRef will decr the
reference count and delete it if it goes to zero. ere is the code:
######################
class ::ReferenceCount {
private variable m_refCnt 0
constructor {} {
# puts "called reference count constructor: $m_refCnt $this";
addRef
}
public method addRef {} {
incr m_refCnt
# puts "Adding Reference count: $m_refCnt $this"
}
public method relRef {} {
incr m_refCnt -1
#puts "Releasing reference count: $m_refCnt $this"
if { $m_refCnt == 0 } {
# puts "deleting reference: $m_refCnt $this"
delete object [namespace which $this]
}
}
public method getObjRef { } {
addRef
return [namespace which $this]
}
} ;# end class ReferenceCount
##################################
just inherit this class in your class
class myClass {
inherits ::ReferenceCount
# yada yada
}
myClass obj
set var [obj getObjRef ] ;# this is a bit cheese
obj relRef ;# object should still exist
$var relRef ;# now the object is toast
I hope this gives you some ideas to delete objects
Kregg
.
- References:
- itcl destructor
- From: Antonio Ceballos
- itcl destructor
- Prev by Date: Re: FlexLM extension?
- Next by Date: Tktable - differnt column width issue
- Previous by thread: Re: itcl destructor
- Next by thread: Re: itcl destructor
- Index(es):
Relevant Pages
|