[omniORB] Re: Object Reference Rules

Armen Yampolsky ayampolsky@erols.com
Wed, 24 Mar 1999 20:57:22 +0000


David, thank you for your quick response!

Unfortunately, even with this simple example, using your suggested code
(Method 3, which you label "if you want to be able to get() again"), we see a
memory leak on the server. The relevant client code looks something like
this:

----------- Java client -----------

ObjFactory factory = .....;  //get from NameService
ObjectHolder holder = .....; //get from NameService
SimpleObject object = SimpleObjectHelper.narrow(factory.createObj());

//this loop will cause the server's memory to swell linearly:
while (true)
{
    holder.put(object);
    object = holder.get();
    object.count(7);
}

// in real life, eventually we would release the
// newly instantiated object...
object.kill();

----------- end Java code -----------

In other words, we want to re-get and re-put the same servant reference
(independently) as many times as we want.

Any ideas?
-Armen




David Riddoch wrote:

> class ObjectHolder_i : public virtual _sk_ObjectHolder {
> public:
>   virtual ~ObjectHolder_i();
>
>   void put(SimpleObject_ptr obj);
>   SimpleObject_ptr get();
>
> private:
>   SimpleObject_var m_held;
> };
>
> void
> ObjectHolder_i::put(SimpleObject_ptr obj)
> {
>   m_held = SimpleObject::_duplicate(obj);
> }
>
> SimpleObject_ptr
> ObjectHolder_i::get()
> {
>   // Method 1
>   SimpleObject_ptr tmp = SimpleObject::_duplicate(m_held);
>   m_held = SimpleObject::_nil();
>   return tmp;
>
>   // Method 2
>   return m_held._retn();
>
>   // Or if you want to be able to get() again ...
>   return SimpleObject::_duplicate(m_held);
> }
>
> Hope this does what you want ...
> David
>
> On Wed, 24 Mar 1999, Armen Yampolsky wrote:
>
> > Hi,
> >
> > Apologies if this question is not entirely omniORB-specific. I am trying
> > to figure out the correct way of passing an object reference from server
> > to client and back again. A simple example IDL would look as follows:
> >
> > -------------------------------
> > interface SimpleObject {
> >     attribute long count;
> >     void kill();    // counterpart to ObjFactory::createObj(), clears
> > server resources.
> > };
> >
> > interface ObjectHolder {
> >     void put(in SimpleObject obj);
> >     SimpleObject get();
> > };
> >
> > interface ObjFactory {
> >     SimpleObject createObj();
> > };
> > -------------------------------
> >
> >
> > Now what I want to do is the following:
> > (1) receive ref to a newly instantiated SimpleObject via
> > ObjFactory::createObj().
> > (2) put it into the ObjectHolder on the server.
> > (3) get it from the ObjectHolder.
> > (4) alter its attribute.
> > (5) put it back in the ObjectHolder.
> > (6) repeat 3-5 as much as I want.
> >
> > Instantiation via ObjFactory::createObj() works fine, we call
> > _obj_is_ready and _this as required by the spec. Modifying the object
> > reference's attribute on the client works fine. SimpleObject::kill()
> > calls _dispose(), and this works correctly as usual. Putting the
> > SimpleObject into the ObjectHolder seems to work fine as well. But
> > here's where the questions arise. In ObjectHolder::get() we can not call
> > _this() on the object prior to returning it, as it is now recognized by
> > the ObjectHolder as a SimpleObject_ptr, which does not have a _this()
> > method. We tried calling _duplicate in the ObjectHolder::put(), but this
> > leaks memory. We then tried adding a CORBA::release() on the new
> > duplicate, but then got OBJECT_NOT_EXIST exception on the client. What
> > is the correct way to implement these methods (ObjecHolder::put and
> > ObjectHolder::get)?
> >
> > Note: Client is in Java, server is omniORB2.7.1 on Solaris 2.6.
>

--
Armen Yampolsky
Axiom Software Labs
New York