Information
We are currently investigating an issue with the editor of some pages. Please save your work and avoid to create new pages until this banner is gone.
...
This approach is valid both for stack and heap instances of an OffShoot:
For the OffShoot servant instance on the stack, you need to make sure to deactivate the OffShoot servant before cb variable goes out of scope. Here you will get compilation issues if you try to deactivate it after going out of scope.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
MyCBImpl cb;
examples::MyCallback_var cbObj = cb._this();
...
//Deactivate the Offshoot servant
PortableServer::POA_var poa = cb._default_POA();
PortableServer::ObjectId_var id = poa->servant_to_id(&cb);
poa->deactivate_object(id.in()); |
For the OffShoot servant instance on the heap, you need to make sure to deactivate the OffShoot servant before destroying the cb variable. Doing it in the reverse order has undefined behavior, usually ending in segmentation fault.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
MyCBImpl* cb = new MyCBImpl();
examples::MyCallback_var cbObj = cb->_this();
...
//Deactivate the Offshoot servant
PortableServer::POA_var poa = cb->_default_POA();
PortableServer::ObjectId_var id = poa->servant_to_id(cb);
poa->deactivate_object(id.in());
// Make sure to delete the OffShoot servant instance after deactivating the CORBA object
delete cb; |
This approach is valid both for stack and heap instances of an OffShoot:
For the OffShoot servant instance on the stack, you need to make sure ORB is stopped before cb variable goes out of scope. The variable going out of scope before stopping the ORB is undefined behavior resulting in segmentation fault in most implementations due to trying to access a memory address in a different stack.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
{
MyCBImpl cb;
examples::MyCallback_var cbObj = cb._this();
...
// Stop ORB
...
} |
For the OffShoot servant instance on the heap, you need to make sure to delete the OffShoot servant instance after ORB is stopped. If the variable is deleted before stopping the ORB has undefined behavior, regularly resulting in segmentation fault due to using a destroyed instance.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
MyCBImpl* cb = new MyCBImpl();
examples::MyCallback_var cbObj = cb->_this();
...
// Stop ORB
...
// Delete the heap OffShoot servant instance
delete cb; |
When working with standalone clients, we need to handle the servant lifecycle of the offshoots/callbacks. There are three approaches: