Archived

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

Smart pointers and proxys

Hi!

I tested the smart pointers, and it works well :) But when I buid a proxy from a smart pointer, the proxy is registered so the smart pointer is never deleted. (logical)

Ged::FolderSeq FolderI::subFolders (const Ice::Current &pCurrent)
{
...
Ged::FolderPtr f = new FolderI (...);
folders.push_back (Ged::FolderPrx::uncheckedCast (pCurrent.adapter->addWithUUID (f)));
...
return folders;
}

Isn't there a way to specify that when a proxy is no more used on a client, then it is automatically destroy, so the smart pointed is freed ???

Or perhaps there's a way to tell Ice to free all unused proxyes ? (because when i create the proxy, it's not yet used...)

Comments

  • From your question, it sounds like you want the servant in the server to be reclaimed when the client drops the proxy to that servant? If so, no, you have to arrange for this to happen yourself. The problem you mention is generally known as distributed garbage collection. General-purpose solutions to this problem are complex and do not scale. (DCOM had such a mechanism, which was a major reason for why DCOM couldn't be used for anything but toy applications.)

    You can deal with your problem by maintaining a timer in the server that is reset whenever the servant is touched; when the timer expires, reclaim the servant in the server. The client is responsible for periodically invoking an operation on the object to prevent it from being reclaimed prematurely.

    The other option is to use an evictor (see the doc). This is simpler than maintaining timers but has the disadvantage that it is possible for a servant to be reclaimed prematurely. However, if you don't have very large numbers of objects, with clients touching nearly all of them most of the time (in other words, if you have reasonable locality of reference), an evictor is the simpler and more efficient way to get rid of stale servants.

    Cheers,

    Michi.