Re: itcl destructor



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


.



Relevant Pages

  • Re: Delivering events from a worker thread using attributed ATL
    ... CMessageHolderSTA passes the call to its base class, ... > reference to the object. ... CMessageHolderSTA has removed the message from the queue so ... >> AddRef. ...
    (microsoft.public.vc.atl)
  • Re: Question on COM EVENT NOTIFICATION
    ... IUnknown's AddRef and Release are satisfied locally, i.e. it performs an AddRef and a Release on the proxy, not on your object. ... So your AddRef and Release don't really make any sense for an out-of-process object, since what you think the reference count is and what the COM subsystem thinks it is are two different things. ... else if(IsEqualIID (riid, __uuidof (IDispatch))) ...
    (microsoft.public.vc.atl)
  • Re: When To AddRef
    ... Using AddRef properly fixes these strange errors. ... If you are not add a reference count when you copy a interface pointer and then release your original pointer, the new pointer behavior became uncertainly. ... the first pointer to the instance, the second one gets invalid, probably because the object released itself and then I get memory access ...
    (microsoft.public.vc.atl)
  • Re: Handling ( Copying) COM Interface reference
    ... i want to know is it safe to copy COM interface pointers and release ... if you watch your reference count carefully. ... AddRef and Release ... crash how to make sure that we do not double delete / release COM ...
    (microsoft.public.vc.language)
  • Re: various objects in my VB6 project - Calling IUnknown
    ... > up AddRef and Release declarations that are legal in VB, and caste, starting ... can I also caste the AddRef/Release ... > the only reference to it remaining, ... destroys itself. ...
    (microsoft.public.vb.general.discussion)