[omniORB] BOA -> POA questions
David Riddoch
djr@uk.research.att.com
Mon, 17 Jul 2000 12:21:51 +0100 (BST)
On Mon, 17 Jul 2000, Masaaki Sekiya wrote:
> > > Looking through your example code in
> > > http://www.uk.research.att.com/omniORB/doc/3.0/omniORB/omniORB002.html#toc9
> > >
> > > I find a call to myecho->_remove_ref() which I don't understand.
> > > Given that the call to _this() increments the ref counter and sets it
>
> I am understanding as below,
> _this() increments the ref counter with omniORB2.8.
> but _this() doesn't increment the ref counter with omniORB3.
Yes...
Unless you are using implicit activation, in which case _this() *might*
increment the ref count the first time it is called on a servant, if that
servant has not already been activated, and _default_POA() returns a
suitable POA, and the policies are right ... ... ... ouch.
I _strongly_ recommend that you do not use implicit activation, because it
seems to confuse the hell out of everyone. Never call _this() on a
servant until after you have activated it. If you stick to this rule,
then _this() will not increment the reference count.
> > > to 1, I would think that a call to 'deactivate_object' sets it back to
> > > 0, resulting in the deletion.
> >
> > When a servant is created it has a reference count of 1. When you
> > activate it, it becomes 2. You then call _remove_ref() to take it back to
> > 1. When you deactivate the servant, it will go to zero and be deleted
> > (once all outstanding requests have completed).
>
> If _this() doesn't change the ref counter,
> it seems to me that both Echo_var and POA refer to a servant
> after _remove_ref() is called.
> Am I misunderstanding ?
Activating an object increments the reference count -- whether that
happens explicitly or implicitly. Reference counting of servants is
completely independent of object references. I seem to be saying this
almost every week, so I'll say it again loudly.
REFERENCE COUNTING OF SERVANTS IS COMPLETELY INDEPENDENT OF OBJECT
REFERENCES.
Holding an object reference makes no different whatsoever to the lifetime
of the object or the servant that is implementing it.
eg.
1 s = new myservant();
id = poa->activate_object(s);
3 ref = s->_this();
s->_remove_ref();
5 poa->deactivate_object(id);
ref->wobble();
The above is perfectly legal, and will result in the servant being
deleted on line 5 (assuming it is derived from RefCountServantBase) and an
OBJECT_NOT_EXIST exception at line 6.
Cheers,
David