[omniORB] Reference counting
David Riddoch
djr@uk.research.att.com
Fri, 14 Jul 2000 15:43:04 +0100 (BST)
Alex,
As David Scott has said in his previous mail, tie implementations are not
derived from RefCountServantBase, so calling _add_ref() and _remove_ref()
on it do nothing at all. A tie implementation will _never_ be deleted by
the ORB itself.
Further, the lifetime of an object is completely unrelated to the
existence (or not) or any local or remote references. In your example you
ask if the object should exist after the reference has been released. The
answer is always yes, regardless of whether the object has a tie
implementation or not, or whether it is reference counted or not.
An object ceases to 'exist' within the ORB only when it is deactivated or
the ORB (or POA) is closed/destroyed. At this point the ORB will call
_remove_ref(). If it is reference counted, it may be deleted
automatically (assuming all other references have been released). If it
is not reference counted, the ORB will not delete it. You must deal with
that yourself. A ServantActivator may help.
Hope that helps,
David
On Fri, 14 Jul 2000, Alex Shabarshoff wrote:
> Hello all,
>
> I have a question about reference counting and object deletition.
>
> This is the interface file:
>
> module dom
> {
> interface Document
> {
> ///...
> };
> };
>
> And the part of program:
>
> dom::Document_ptr MakeDocument() // actualy this is method of another
> // object
> {
> POA_dom::Document_tie<DOM_Document> * result =
> new POA_dom::Document_tie<DOM_Document>( new DOM_Document() );
> dom::Document_ptr tempPtr = result->_this();
> result->_remove_ref(); // decrements refcount from 2 to 1
> return tempPtr;
> }
>
> ...
> {
> dom::Document_var doc = MakeDocument(); // i'm sure this is only
> // reference to dom::Document object
> }
> // should the servant object exist after this line?
> ...
>
> Inspecting the code under debugger i found what _remove_ref() does not
> even called at servant object POA_dom::Document_tie<DOM_Document> when
> destructor of dom::Document_var is called. It looks like the servant
> object deleted only after call to destroy(1,1) from POA. I'm using
> omniORB3 pre3 and tie interfaces.
>
> omniidl command line was:
> omniidl -bcxx -Wbh=.h -Wbs=SK.cpp -DNO_NS_HACK -Wbtp -I../../../idl dom.idl