This forum has been archived. Please start a new discussion on GitHub.

Question about objectAdapter

In my scenario, one client have to connect to different servers dynamically and each connection is bidir.
Here is my codes:

/* The proxies to _server1 and server2 are dynamically * gotten .

_objectAdapter1=_communicator.createObjectAdapter ("adapter1");
Ice.Identity ident; ="OrNot";
ident.category = "";
_objectAdapter1.add(new CallbackI(), ident);

_objectAdapter2=_communicator.createObjectAdapter ("adapter2");
Ice.Identity ident; ="OrNot";
ident.category = "";
_objectAdapter2.add(new CallbackI(), ident);

* Later, all the stuffs are not needed any longer and
* should be released then.


My question is:
1) Is it correct so far as to what I did? Any advice to imporve it?

2) Since I can not find a method like this:

does it mean that the objectAdapters will not be erased from the hashtable until the communicator is shutdowned?

If so, in my scenario, if will it result in that the items of the hashtable will be cumulated and may lead to the memory is exhausted one day because all my dynamical connections to the servers may be random ?
How do I release a objectAdapter which are useless any more?
Sorry,maybe I misunderstand something and my worries are not necessary but hope getting a clarify.

Thanks in advance.



  • bernard
    bernard Jupiter, FL
    To cleanup an object adapter, you need to deactivate this adapter and "wait for deactivate" this adapter:


    If you're also shutting down or destroying your communicator, you don't need to worry about these calls: _communicator->deactivate() deactivates all object adapters, _communicator->waitForShutdown() waits for the deactivation of all object adapters; _communicator->destroy() do all this as well if it wasn't done previously.

  • Thank you,Bernard.

    When an objectAdapter was created, the hashtable in the objectAdapterFactory will increase one item and keep this adapter :

    adapter = new Ice.ObjectAdapterI(_instance, _communicator, name);
    _adapters[name] = adapter;

    When I don't need this adapter any longer and release all the stuffs by deactiving and waitfordeactiving , how will the hashtable change? I mean, if the hashtable will automatically erase the item relative to that adapter?
    I noticed that in the method objectAdapterFactory.waitForShutdown() , there is a line :

    If is this the only chance to erase an adapter?

  • marc
    marc Florida
    Adapters can be deactivated, but not removed from a communicator. Why do you create so many adapters in the first place? A more typical scenario is that your create only a few adapters (in most cases just one) and use these until you destroy your communicator.
  • hi,Marc,
    In my scenario, one client has to connect to different servers dynamically at the same time and each connection is bidir. I now have a new solution but not very sure , could you please clarify it for me?

    _objectAdapter=_communicator.createObjectAdapter ("adapter");
    Ice.Identity ident; ="OrNot";
    ident.category = "";
    _objectAdapter.add(new CallbackI(), ident);

    Ice.Identity ident; ="OrNot";
    ident.category = "";

    Since the ICE run time is thread safe , then what I should do is to guarantee to the thread safe of the callbackI.

    Any help is appreciated.


  • marc
    marc Florida
    The solution is correct. Just set the OA for each connection that is established from the client to a server. There is no need for more than one object adapter.

    You might want to increase the number of threads in the client-side thread pool, because callbacks that arrive over an outgoing connection are dispatched by the client-side thread pool, and not the server-side thread pool or per-OA thread pool. The default is just one thread.
  • Thank you ,Marc. ICE is really good.
    Last question:
    If I did not need a connection to one server, I just simply do : _server1.ice_connection().close(false);
    This will not affect other connections and the OA, will this?

  • marc
    marc Florida
    This is correct.