[omniORB] basic parameter passing question

Lolke B. Dijkstra omniorb at dijkstra-ict.com
Thu Dec 1 11:37:10 GMT 2005


Anthony Shipman wrote:

>On Thursday 01 December 2005 03:18, you wrote:
>  
>
>>In the way this following code works:
>>
>>    isdn::BChannelControlClient_var retval = bchan->getControl();
>>    return retval._retn();
>>
>>The _var makes a copy of the ref (if required) and when it is destructed
>>(goes out of scope), it removes that copy.
>>
>>The problem with your first case is that you're making TWO copies of the
>>ref and the server side stub only takes ownership of one of the copies.
>>
>>    
>>
>
>As I understand it, in the first case the _var is cast to a _ptr and then 
>passed to duplicate(). So there is only one copy of the ref being made.
>
>  
>
Again:

1.  isdn::BChannelControlClient_var retval = bchan->getControl();
2.  return retval._retn();

1. the call to bchan->getControl() returns a pointer to an object that 
is that assigned to retval so reval becomes the owner
2. you return the internal pointer and instruct retval to give up ownership


In:

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

you also call bchan->getControl() but you do not assign the pointer to a ref, so nothing takes ownership of the return value of bchan->getControl() hence your leak.

You can check what I just said by doing:
	
1.  isdn::BChannelControlClient_var retval = bchan->getControl();
2.  return isdn::BChannelControlClient::_duplicate( retval._in() );

Now the leak disappears







More information about the omniORB-list mailing list