[omniORB] Destroying itself

Clarke Brunt clarke.brunt at trafficmaster.co.uk
Wed May 10 11:55:39 BST 2006


> ...
> (b) Derive your servant from RefCountServantBase and call
> _remove_ref() after poa->deactivate_object(). I have made
> some tests and up to now the object gets properly destructed
> in all cases. Perhaps somebody can confirm that this is a safe way to
> proceed. 

I've regularly used something like this - it works fine. Just make sure that
calls to _remove_ref match up with any (usually implicit) calls to _add_ref.
You must create your servant with 'new' initially (since the reference
counting mechanism is going to use 'delete' on it). You get one implicit
_add_ref from 'new'. A usage pattern I've seen frequently is to call
_remove_ref once you have activated the object. During activation the POA
will have gained a reference, so you can remove your own reference from
'new' and leave the only reference in the POA. When the POA finally
deactivates the object (which as has been said doesn't happen until method
invocations complete) it will do a _remove_ref and the object will be
deleted.

So to summarise: assuming you haven't done anything which gains more
references (see specification) then you need one call to _remove_ref
somewhere. You can do this once you have activated the object (so the POA
has a reference), or leave it till later, as suggested above.

-- 
Clarke Brunt, Principal Software Engineer, Trafficmaster




More information about the omniORB-list mailing list