Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://rtm-cs.sinp.msu.ru/manual/mico/doc/node48.html
Дата изменения: Mon Jun 7 21:54:58 1999 Дата индексирования: Mon Oct 1 21:22:19 2012 Кодировка: |
With the POA, implementations do not inherit from CORBA::Object. Consequently, memory management for servants is the user's responsibility. Eventually, a servant must be deleted with C++'s delete operator, and a user must know when a servant is safe to be deleted - deleting a servant that is still known to a POA leads to undesired results.
CORBA 2.3 addresses this problem and introduces reference counting for servants. However, to maintain compatibility, this feature is optional and must be explicitly activated by the user. This is done by adding POA_PortableServer::RefCountServantBase as a base class of your implementation:
class HelloWorld_impl :
virtual public POA_HelloWorld
virtual public PortableServer::RefCountServantBase
{
...
}
This activates two new operations for your implementation, _add_ref() and _remove_ref(). A newly constructed servant has a reference count of 1, and it is deleted automatically once its reference count drops to zero. This way, you can, for example, forget about your servant just after it has been created and activated:
HelloWorld_impl * hw = new HelloWorld_impl;
HelloWorld_var ref = hw->_this(); // implicit activation
hw->_remove_ref ();
During activation, the POA has increased the reference count for the servant, so you can remove your reference immediately afterwards. The servant will be deleted automatically once the object is deactivated or the POA is destroyed. Note, however, that once you introduce reference counting, you must keep track of the references yourself: All POA operations that return a servant (i.e. id_to_servant() will increase the servants' reference count. The PortableServer::ServantBase_var class is provided for automated reference counting, acting the same as CORBA::Object_var does for Objects.