4 virtual public POA_Hello
9 ACE_DEBUG ((LM_DEBUG
, "Hello_impl::Hello_impl()\n"));
14 ACE_DEBUG ((LM_DEBUG
, "Hello_impl::~Hello_impl()\n"));
24 getRefCount (PortableServer::ServantBase
* sb
)
26 return sb
->_refcount_value ();
30 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
35 CORBA::ORB_init (argc
, argv
);
37 CORBA::Object_var poa_object
=
38 orb
->resolve_initial_references("RootPOA");
40 PortableServer::POA_var poa
=
41 PortableServer::POA::_narrow (poa_object
.in ());
43 if (CORBA::is_nil (poa
.in ()))
44 ACE_ERROR_RETURN ((LM_ERROR
,
45 " (%P|%t) Panic: nil RootPOA\n"),
49 ACE_NEW_RETURN (h
,Hello_impl
, 1);
51 CORBA::ULong before_act
= h
->_refcount_value ();
53 ACE_DEBUG ((LM_DEBUG
, "Before activation: %d\n", before_act
));
55 PortableServer::ObjectId_var oid
= poa
->activate_object (h
);
57 CORBA::ULong after_act
= h
->_refcount_value ();
59 ACE_DEBUG ((LM_DEBUG
, "After activation: %d\n", after_act
));
62 * C++ Language Mapping (formal/03-06-03), section 1.37.3 (Servant
63 * Memory Management Considerations), first bullet on page 1-136:
65 * POA::id_to_servant returns a Servant. The POA invokes _add_ref
66 * once on the Servant before returning it; the caller of
67 * id_to_servant is responsible for invoking _remove_ref on the
68 * returned servant when it is finished with it.
71 CORBA::ULong refCountBeforeIdToServant
=
72 h
->_refcount_value ();
74 ACE_DEBUG ((LM_DEBUG
, "Before id_to_servant: %d\n", refCountBeforeIdToServant
));
76 PortableServer::ServantBase_var srv
= poa
->id_to_servant (oid
.in());
78 CORBA::ULong refCountAfterIdToServant
=
79 srv
->_refcount_value ();
81 ACE_DEBUG ((LM_DEBUG
, "After id_to_servant: %d\n", refCountAfterIdToServant
));
84 * According to the above quote, this assertion shall be true.
86 ACE_ASSERT (refCountAfterIdToServant
== refCountBeforeIdToServant
+ 1);
89 * At the end of this scope, "srv" is destructed, which decrements
90 * the servant's reference count.
94 CORBA::ULong before_deact
= h
->_refcount_value ();
96 ACE_DEBUG ((LM_DEBUG
, "Before deactivate_object: %d\n", before_deact
));
98 poa
->deactivate_object (oid
.in());
101 * Because id_to_servant did not increment the reference count, but
102 * the reference count was decremented by the "srv" destructor, the
103 * reference count, using TAO 1.4.5, is now 0, and the servant has
104 * been destructed. So the following will crash, despite being
108 CORBA::ULong after_deact
= h
->_refcount_value ();
110 ACE_DEBUG ((LM_DEBUG
, "After deactivate_object: %d\n", after_deact
));
114 orb
->shutdown (true);
118 catch (const CORBA::Exception
& ex
)
120 ex
._tao_print_exception ("Exception caught:");