Discussion:
[omniORB] memory leaking, about LocalObject's _var type
未知 元素
2006-08-19 10:20:17 UTC
Permalink
Hi:
I'm using OMNIORB_4_1_0_BETA_2
I build instance( of local interface ) repeatedly and assign it to same
_var type variable. It seems that the memory allocated last time was not
released.
Following is the test:
// test.idl
#include <orb.idl>

local interface testinterface
{
};

//test_i.cc
// g++ -I. -I /usr/local/include/omniORB4 -L /usr/local/lib -lomniORB4 *.cc
//
// Example code for implementing IDL interfaces in file test.idl
//

#include <iostream>
#include <test.hh>

class testinterface_i: public testinterface {
public:
// standard constructor
testinterface_i();
virtual ~testinterface_i();

};

testinterface_i::testinterface_i(){
// add extra constructor code here
}
testinterface_i::~testinterface_i(){
std::cerr << std::endl<<"~testinterface_i()"<<std::endl;
}

int main(int argc, char** argv)
{
try {
// Initialise the ORB.
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
// test.Built instance repeatedly and assign it to t.
testinterface_var t;
for( int i=0; i< 30000000; i++)
{
// It seems that the memory allocated last time was not released.
t = new testinterface_i();
}
orb->destroy();
}
catch(...)
{
std::cerr << "An error was catched."<<std::endl;
}
return 0;
}

_________________________________________________________________
Ãâ·ÑÏÂÔØ MSN Explorer: http://explorer.msn.com/lccn
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.idl
Type: text/x-idl
Size: 58 bytes
Desc: not available
Url : http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20060819/c27ba6db/test.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_i.cc
Type: text/x-c++src
Size: 980 bytes
Desc: not available
Url : http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20060819/c27ba6db/test_i.bin
Duncan Grisby
2006-08-19 19:39:36 UTC
Permalink
Post by 未知 元素
I'm using OMNIORB_4_1_0_BETA_2
I build instance( of local interface ) repeatedly and assign it to
same _var type variable. It seems that the memory allocated last time
was not released.
You need to implement your own reference counting functions. Don't ask
me why, but the C++ mapping says that the default reference counting
functions are empty. See section 1.35 of the C++ mapping specification,
version 1.1:

_add_ref

The _add_ref member function is called when the reference is
duplicated. A default implementation is provided that does nothing.
A derived implementation may use this operation to maintain a
reference count.

_remove_ref

The _remove_ref member function is called when the reference is
released. A default implementation is provided that does nothing. A
derived implementation may use this operation to maintain a
reference count, and delete the object when the count becomes zero.

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Wernke zur Borg
2006-08-21 18:52:00 UTC
Permalink
Sent: 19 August 2006 06:20
Subject: [omniORB] memory leaking, about LocalObject's _var type
I'm using OMNIORB_4_1_0_BETA_2
I build instance( of local interface ) repeatedly and
assign it to same
_var type variable. It seems that the memory allocated last
time was not
released.
You should derive your servants from RefCountServantBase and use
_remove_ref() to dispose of the servant. Note that the constructor
already increments the ref count, therefore you have to explicitly call
_remove_ref() when you are done with the object. It is not enough to use
the servant_var assignment operator. It seems strange anyway to use an
object reference variable to hold an instance of a servant. Normally you
would use a servant pointer for it I believe.

Regards, Wernke
Duncan Grisby
2006-08-21 19:49:23 UTC
Permalink
Post by Wernke zur Borg
Post by 未知 元素
I'm using OMNIORB_4_1_0_BETA_2
I build instance( of local interface ) repeatedly and
assign it to same
_var type variable. It seems that the memory allocated last
time was not
released.
You should derive your servants from RefCountServantBase and use
_remove_ref() to dispose of the servant. Note that the constructor
already increments the ref count, therefore you have to explicitly call
_remove_ref() when you are done with the object. It is not enough to use
the servant_var assignment operator. It seems strange anyway to use an
object reference variable to hold an instance of a servant. Normally you
would use a servant pointer for it I believe.
He's talking about local interfaces, not normal interfaces. There is no
servant class in that case, just the interface implementation. Local
interface support is a new feature in omniORB 4.1.

As an aside, omniORB 4.1 also deprecates RefCountServantBase as required
by the 1.1 version of the C++ mapping. Now the reference counting
behaviour is in the base ServantBase class.

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Loading...