[omniORB] strange asymmetric behavior
Clarke Brunt
clarke at lsl.co.uk
Mon Jul 21 14:46:50 BST 2003
> I noticed a strange behavior in OmniORB 4.01 when an obj ref. is taken
> within the context of servant code.
> Assume a servant Console obj (which inherits from RefCountServantBase as
> usual)
> is created and activated. Then next line of code:
>
> Console_var cv = console->_this();
>
> causes the side effect of increasing the ref. counter pd_refCount of
target
> servant, depending on the context where this is performed. This is decided
> in PortableServer::ServantBase::_do_this() - in portableserver.cc - if
> current is not the servant itself and there are no activations (or more
than
> one).
> Then omniOrbPOA::servant__this() is called, which in turn performs the
> _add_ref().
>
> The bad news are that one would expect this side effect to be reversed
when
> obj ref. goes out of scope, thus decreasing the servant ref. counter. But
> this never occurs (no _remove_ref()), and this servant will never be
> destroyed after deactivation since application code doesn't now anything
> about this counter being increased.
> Any comment?
I thought this was just the way it was meant to work. The ref count starts
at 1 when the servant is constructed with 'new'. If the call to _this()
activates it (using implicit activation), then there is now a reference to
it in the POA, and the reference count is therefore increased (now at least
2). It is not the job of xxx_var to do _remove_ref - don't confuse reference
counting of object references with reference counting of servants. If you
want the object to be automatically deleted once it it deactivated, then you
need to ensure that you are no longer holding on to the reference gained in
'new', so you need to put an explicit call to _remove_ref() somewhere.
Obviously this can't be done before the object is activated, otherwise it
will be deleted before it is activated, but you can do this _remove_ref() as
soon as you are certain that the object has been activated (either by the
first call to _this(), or an explicit activate_object, or whatever).
--
Clarke Brunt, Principal Software Engineer, Yeoman Navigation
More information about the omniORB-list
mailing list