[omniORB] Failure to dispose of server object when used in a factory.

Jonathan Oddy jonathan.oddy@man.brite.co.uk
Wed, 3 Feb 1999 12:23:29 -0000


This is a multi-part message in MIME format.

------=_NextPart_000_0038_01BE4F70.02100B90
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit


Could somebody help please.  I have the following two factory
implementations - each returning references to newly created Server objects.
I am comfortable with the Factory1 scenario - here everything behaves as I
suspect (ie NewServer1() returns an instance and DeleteServer1 deletes it).

However the Factory2 scenario does not work how I would like.  NewServer2
creates a server instance, however DeleteServer2 does not delete it.  The
reason for this behavior (I believe) is that when calling DeleteServer2 the
reference count of pSrv is 2 (I assume this is because the parameter pSrv is
a second reference to my server object).  Can somebody explain how I can get
scenario 2 (or similar) to work the way I would like?


class Server_i
{
public:
  //  this is never called when using Factory2_i
  ~Server_i() { cout << "Server_i::DTOR called" << endl; }
}

class Factory1_i
{
public:
  Server_ptr NewServer1()
  {
    pServer1 = new Server_i();
    pServer1->_obj_is_ready(pServer1->_boa());
    return pServer1->_this();
  }
  CORBA::Short DeleteServer1()
  {
    pServer1->_dispose();
  }

private:
  Server_i *pServer1;
}

class Factory2_i
{
public:
  Server_ptr NewServer2()
  {
    Server_i * p = new Server_i();
    p->_obj_is_ready(p->_boa());
    return p->_this();
  }
  // ref count of pSrv always 2 when the function is called
  // hence pSrv never deleted
  CORBA::Short DeleteServer2(Server_ptr pSrv)
  {
    CORBA::release(pSrv);
    return TRUE;
  }
}

I have looked/followed various discussions of factories within the OmniORB
mailing list/archives but can not find the answer to my problem.

Thanks in advance
  Jonathan

Software Team Leader - NT Development
Brite Voice Systems
Brite Court - Park Road - Gatley - Cheshire - SK8 4HZ - ENGLAND

tel/fax: +44(0) 161 495 1128/1001



------=_NextPart_000_0038_01BE4F70.02100B90
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =
size=3D2>Could=20
somebody help please.&nbsp; I have the following two factory =
implementations -=20
each returning references to newly created Server objects.&nbsp; I am=20
comfortable with the Factory1 scenario - here everything behaves as I =
suspect=20
(ie NewServer1() returns an instance and DeleteServer1 deletes =
it).&nbsp;=20
</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2>However the Factory2 scenario does not work how I would =
like.&nbsp;=20
NewServer2 creates a server instance, however DeleteServer2 does not =
delete=20
it.&nbsp; The reason for this behavior (I believe) is that when calling=20
DeleteServer2 the reference count of pSrv is 2 (I assume this is because =
the=20
parameter pSrv is a second reference to my server object).&nbsp; Can =
somebody=20
explain how I can get scenario 2 (or similar) to work the way I would=20
like?</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =
size=3D2>class=20
Server_i </FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2>{</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2>public:</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp; //&nbsp; this is never called when using=20
Factory2_i</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp; ~Server_i() { cout &lt;&lt; =
&quot;Server_i::DTOR=20
called&quot; &lt;&lt; endl; }</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2>}</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =
size=3D2>class=20
Factory1_i</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>{</FONT></SPAN></DIV>
<DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =
size=3D2>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2>public:</FONT></SPAN></DIV>&nbsp; Server_ptr=20
NewServer1()</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp; {</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; p<SPAN =
class=3D554370312-03021999><FONT=20
color=3D#000000 face=3DArial size=3D2>Server1</FONT></SPAN> =3D new=20
Server_i();<BR>&nbsp;&nbsp;&nbsp; p<SPAN =
class=3D554370312-03021999><FONT=20
color=3D#000000 face=3DArial =
size=3D2>Server1</FONT></SPAN>-&gt;_obj_is_ready(p<SPAN=20
class=3D554370312-03021999><FONT color=3D#000000 face=3DArial=20
size=3D2>Server1</FONT></SPAN>-&gt;_boa());</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; return p<SPAN=20
class=3D554370312-03021999><FONT color=3D#000000 face=3DArial=20
size=3D2>Server1-&gt;_this()</FONT></SPAN>;</FONT></DIV>&nbsp;=20
}</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp; CORBA::Short =
DeleteServer1()</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp; {</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
pServer1-&gt;_dispose();</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =
size=3D2>&nbsp;=20
}</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2>private:</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp; Server_i =
*pServer1;</FONT></SPAN></DIV></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2>}</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =
size=3D2>class=20
Factory2_i</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>{</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2>public:</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp; Server_ptr NewServer2()</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp; {</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><FONT size=3D2>&nbsp;&nbsp;&nbsp; Server_i * p =
=3D new=20
Server_i();<BR>&nbsp;&nbsp;&nbsp;=20
p-&gt;_obj_is_ready(p-&gt;_boa());</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; return <SPAN =
class=3D554370312-03021999><FONT=20
color=3D#000000 face=3DArial =
size=3D2>p-&gt;_this()</FONT></SPAN>;</FONT></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp; }</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp; // ref count of pSrv always 2 when the =
function is=20
called</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp; // hence pSrv never =
deleted</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp; CORBA::Short DeleteServer2(Server_ptr=20
pSrv)</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp; {</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
CORBA::release(pSrv);<BR>&nbsp;&nbsp;&nbsp;=20
return TRUE;</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =
size=3D2>&nbsp;=20
}</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2></FONT></SPAN><SPAN =
class=3D554370312-03021999><FONT=20
color=3D#000000 face=3DArial size=3D2>}</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV>
<DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =
size=3D2>I have=20
looked/followed various discussions of factories within the OmniORB =
mailing=20
list/archives but can not find the answer to my =
problem.</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN>&nbsp;</DIV></DIV></DIV>
<DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =
size=3D2>Thanks=20
in advance</FONT></SPAN></DIV>
<DIV><SPAN class=3D554370312-03021999><FONT color=3D#000000 face=3DArial =

size=3D2></FONT></SPAN><SPAN class=3D554370312-03021999><FONT =
color=3D#000000=20
face=3DArial size=3D2>&nbsp; Jonathan </FONT></SPAN></DIV></DIV>
<P><!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN"></P><FONT =
color=3D#0000ff>
<P><FONT face=3DArial><FONT size=3D1>Software Team Leader - NT =
Development<BR>Brite=20
Voice Systems<BR>Brite Court - Park Road - Gatley - Cheshire - SK8 4HZ - =

ENGLAND<BR><BR>tel/fax: +44(0) 161 495 =
1128/1001</FONT></FONT></FONT><FONT=20
size=3D1><FONT face=3DArial><FONT color=3D#0000ff> =
</FONT></FONT></FONT></P><FONT=20
color=3D#0000ff></FONT>
<DIV>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0038_01BE4F70.02100B90--