[omniORB] basic parameter passing question

Lolke B. Dijkstra omniorb at dijkstra-ict.com
Wed Nov 30 09:45:34 GMT 2005


Anthony Shipman wrote:

>A server of mine has an object reference stored as:
>
>isdn::BChannelControlClient_var	ctlObj_;
>
>isdn::BChannelControlClient_var&
>BChannel::getControl()
>{
>    return ctlObj_;
>}
>
>
>A method of an interface wants to return this object reference. 
>
>isdn::BChannelControlClient_ptr
>Service_impl::new_client(...)
>{
>   ...
>   return isdn::BChannelControlClient::_duplicate(bchan->getControl());
>}
>
>The Michi+Henning book says that the caller of new_client() is responsible for 
>releasing the returned object reference. This says to me that I must
>duplicate the reference before returning it. Is this correct?
>
>With omniORB 4.0.5 I find that there is a memory leak. I'm told that the leak 
>goes away if I return the reference like this.
>
>    isdn::BChannelControlClient_var retval = bchan->getControl();
>    return retval._retn();
>
>As far as I can tell this code should be exactly equivalent to the use of 
>duplicate. Does this make sense to anyone? 
>
>  
>
Yes this is what you could expect indeed. In:

   	return isdn::BChannelControlClient::_duplicate(bchan->getControl());

you call bchan->getControl() but also here!! you are responsible for releasing the ref as in:

	isdn::BChannelControlClient_var dummy = bchan->getControl()
	if you then _duplicate you should be fine

however your second approach makes more sence, there you just tell retval to give up ownership

hope this helps








More information about the omniORB-list mailing list