[omniORB] Confusion over different 'release' functions for a pointer....

David Riddoch djr@uk.research.att.com
Thu, 6 Jul 2000 11:31:33 +0100 (BST)


On Thu, 6 Jul 2000, Ben Miller wrote:

> Hi all, I'm having some problems getting my head around how I should
> free-up my CORBA objects.
> 
> In my client program, if I have a pointer to an interface (created by
> the server) like this...
> 
> mlcs::DLM_ptr dlm_obj_ptr = svr_obj_ref->createDLMInterface();
> 
> ...I am confused as to the differences between...
> 
> 1.  CORBA::release(obj_ptr);
> 2.  obj_ptr->_remove_ref();

1. is the correct way to release an object reference.

2. is totally bogus -- that method does not even exist for object
references.  It is used for reference counting on Servants (object
implementations).


> If I used the smart-style pointer, like this...
> 
> mlcs::DLM_var dlm_obj_ptr = svr_obj_ref->createDLMInterface();
> 
> ...what would the destructor call to release the underlying object?

The destructor uses CORBA::release() to release the object _reference_.
This has no effect whatsoever on the underlying object.


> Also, am I right in thinking that I should never explicitly 'delete' a
> server object implementation, even if I called 'new' on it?

You should never explicitly delete a ref-counted Servant (one derived
from PortableServer::RefCountServantBase), but you can explicitly delete
normal Servants if you allocated them with 'new'.  You must be very
careful to ensure that all outstanding requests have completed first
though...

I get the impression you are a little confused about the relationship
between objects, references and servants.  I suggest you read 'Advanced
CORBA Programming with C++' by Henning and Vinoski.


Hope that helps,
David