[omniORB] object references management

David Riddoch djr@uk.research.att.com
Mon, 20 Mar 2000 14:58:30 +0000 (GMT)


Jorge,


You are releasing the object reference, but not deactivating the server
object.  At some point you need to do poa->deactivate_object() or
something equivalent to cleanup the servant itself.  An easy way to do
this is to have a method in the object's interface -- however you could
still get leaks if a client crashes.

You also need to do new_servant->_remove_ref() after activate_object() in
da_objeto() to get your reference counting right.


Cheers,
David



On Mon, 20 Mar 2000, [iso-8859-1] Jorge Garc=EDa Velasco wrote:

> Hi,
>=20
>   I have a question about which is the correct method in omniORB to retur=
n and release object references.
> =20
>   Currently I'm using omniORB3 prerelease 2 (snapshot omniORB3-20000316).=
  =20
> =20
>   I've done an example where the client calls a remote method which retur=
ns an object reference. The client gets this reference and calls one of it'=
s methods. After that, the client deallocates this reference.
>=20
>   All runs right but I have a memory leak in the server side, it seems li=
ke the client cannot deallocates the remote reference correctly.
>=20
>   Below there are some fragments of the client / server code.
>=20
>   Is this code correct ?.
>=20
>=20
>   Thanks in advanced.
>=20
>=20
>     Jorge Garcia.
>=20
>     R&D Software Engineer
>     Mabyc, S.A.
>     Barcelona (Spain)
>=20
>=20
>=20
> SOURCE CODE
> -----------=20
>=20
> libreria.idl
> ------------
>=20
> #ifndef __LIBRERIA_IDL__
> #define __LIBRERIA_IDL__
>=20
> module Libreria
> {
>  interface Funciones
>  {
>   Funciones da_objeto();
>   void show();
>  };
> };
>=20
> #endif
>=20
>=20
> servidor.cc
> -----------
> ....
> ....
>=20
> class Libreria_i : public virtual POA_Libreria::Funciones,=20
>                    public PortableServer::RefCountServantBase
> {
>  public:
>   inline Libreria_i() {} =20
>   virtual ~Libreria_i() {}
>   virtual Libreria::Funciones_ptr da_objeto();
>   virtual void show();
> };
>=20
> void Libreria_i::show()
> {
>  cout << "Hello" << endl;
> }
>=20
> Libreria::Funciones_ptr Libreria_i::da_objeto()
> {
>  Libreria_i* new_servant=3Dnew Libreria_i;
>=20
>  poa->activate_object(new_servant);
>=20
>  return new_servant->_this();
> }
>=20
> ....
> ....
>=20
>=20
> cliente.cc
> ----------
>=20
> ....
> ....
>=20
> Libreria::Funciones_ptr ret_val;
>=20
> while(true)
> {
>  ret_val=3De->da_objeto();
>=20
>  ret_val->show();
>=20
>  CORBA::release(ret_val);
> }
>=20
> ....
> ....
>=20
> =20
>=20
>=20
>=20
>=20
>=20