[omniORB] problem with server memory deallocation

risc risc riscman77 at gmail.com
Sun Apr 18 12:47:06 BST 2010


Hi Duncan,

thanks for your reply. I see the leak because i don't see the print of
object destructor when the object is cancelled. I try to post a minimal
example

IDL FILE:


module test
{
  interface p1
   {
    attribute  string name;
   };
  interface p2
  {
    p1 function();
  };

};


CLIENT:



    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);


    if( argc != 2 ) {
      cerr << "usage:  eg2_clt <object reference>" << endl;
      return 1;
    }

    CORBA::Object_var obj = orb->string_to_object(argv[1]);



     test::p2_var pd=test::p2::_narrow(obj);

   if( CORBA::is_nil(pd) ) {

       cerr << "Can't narrow reference to type Echo (or it was nil)." <<
endl;
       return 1;
    }


 test::p1_var l=pd->function();

 l->name();

 orb->destroy();

 }





SERVER:


class test_p1_i: public POA_test::p1 {
private:

public:
  // standard constructor
  test_p1_i();
  virtual ~test_p1_i();

  // methods corresponding to defined IDL attributes and operations
  void name(const char*);
  char* name();

};

//
// Example implementational code for IDL interface test::p1
//

test_p1_i::test_p1_i(){
  // add extra constructor code here
  cout<<"constructor Call"<<endl;
}
test_p1_i::~test_p1_i(){
  // add extra destructor code here
 cout<<"Destructor Call"<<endl;
}
//   Methods corresponding to IDL attributes and operations
void test_p1_i::nome(const char*){
  // insert code here and remove the warning

}

char* test_p1_i::name(){

  // insert code here and remove the warning

}



class test_p2_i: public POA_test::p2 {
private:

public:
  // standard constructor
  test_p2_i();
  virtual ~test_p2_i();

  // methods corresponding to defined IDL attributes and operations
  test::p1_ptr function();

};

//
// Example implementational code for IDL interface test::p2
//

test_p2_i::test_p2_i(){

cout<<"Constructor p2"<<endl;
}
test_p2_i::~test_p2_i(){

 cout<<"destructor p2"<<endl;
}
//   Methods corresponding to IDL attributes and operations

test::p1_ptr test_p2_i::function(){
  // insert code here and remove the warning
  test_p1_i * n=new test_p1_i;

  n->name("Alfred");


  test::p1_var ret=n->_this();

  n->_remove_ref();

 return  ret._retn();
}



// End of example implementational code



int main(int argc, char** argv)
{
  try {
    // Initialise the ORB.

    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    // Obtain a reference to the root POA.
    CORBA::Object_var obj = orb->resolve_initial_
references("RootPOA");
 poa = PortableServer::POA::_narrow(obj);

    // We allocate the objects on the heap.  Since these are reference
    // counted objects, they will be deleted by the POA when they are no
    // longer needed.
      test_p2_i* mytest_p2_i = new test_p2_i();


    // Activate the objects.  This tells the POA that the objects are
    // ready to accept requests.
     PortableServer::ObjectId_var mytest_p2_iid =
poa->activate_object(mytest_p2_i);


    // Obtain a reference to each object and output the stringified
    // IOR to stdout
     {
      // IDL interface: test::p2
      CORBA::Object_var ref = mytest_p2_i->_this();
      CORBA::String_var sior(orb->object_to_string(ref));
      std::cout << "IDL object test::p2 IOR = '" << (char*)sior << "'" <<
std::endl;
    }



    // Obtain a POAManager, and tell the POA to start accepting
    // requests on its objects.
    PortableServer::POAManager_var pman = poa->the_POAManager();
    pman->activate();

    orb->run();
    orb->destroy();
  }
....


I See after the client make orb->destroy() the cout in the P1 destroctor is
not be called.

Thanks
Best Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20100418/a32279ed/attachment.htm


More information about the omniORB-list mailing list