[omniORB] Destructor and Factories

Ole Storm storm@ifad.dk
Fri, 11 Dec 1998 10:56:55 +0100


Hi Martin,

Martin Renner wrote:
> 
> Hi.
> 
> >To destroy the server object you have to use the _boa()->dispose(obj)
> >call, which will destroy the object when its server-local reference
> >count hits zero.
> 
> Exactly this is my problem: When should I call dispose()?
> 
> My factory will produce about 10000 objects (no typo) and under normal
> circumstances, the corba-server will be up for several months. So the
> client has to show somehow that he doesn't want to use an object-reference
> any longer (an object-reference which the server explicitly created for
> this client).
> 
> One solution would be, that the client calls a oneway-method of this
> object, which contains something like "_boa->dispose(this)", but that's
> ugly, ugly!

I had exactly the same problem with a CORBA application I implemented some
time ago. My "dilemma" ended with the (ugly or at least not too nice)
solution of exposing a "destroy()" method in each interface. Using this
method "well-behaved" clients can clean up nicely when finished using an
object. Unfortunately the client code will then be filled with annoying
calls to destroy(), and the client programmer will have to consider for each
object if it is safe to call destroy() at a given point. I.e. the benefit of
using _var object references is completely lost!

> Is there no other way, how I can delete objects, that the client doesn't
> want to use any longer?

I think there are at least two ways to make the programming of the client
more simple when using the destroy() based solution:

1. Use Smart-Proxies as described in the User Guide for omniORB (Section 8.2
of the user guide for omniORB 2.4). For each interface you could then catch
the destruction of the proxy object and here call the destroy() method of
the server object. In this way the client code would never explicitly call
destroy().

2. Equip each factory interface with a Tag() and DestroyTag() method to
destroy (or dispose) several server objects. The semantics of the Tag()
method would be to push a unique tag onto a stack of tags. Each object
created by the factory would then always be tagged with the tag value stored
on top of the stack. A call to DestroyTag() would pop the topmost tag value
of the stack and call _boa->dispose() on each server object tagged with
exactly this tag value. Notice that the stack-approach makes it possible to
"nest" the calls to Tag():

main()
{
  // Some initialization
  fact->Tag();

  // create some objects
  fact->Tag();

  // create more...	

  // And destroy all objects created since the last call to Tag()	
  fact->DestroyTag();

  f();

  // And finally clean up everything:
  fact->DestroyTag();
}

void f(void)
{
  fact->Tag();
  
  // Do something...

  fact->DestroyTag();
}


Hope this can be of any use.

For your information I used solution 2 above. If you consider solution 1 you
should be aware that there is a slight error in the example of how to write
your own proxy object factories (at least in the documentation for v. 2.4).
Sai-Lai provided me with a patch some thim ago that I will naturally share
with you if you are interested.

Best regards,

	Ole.

---------------------------------------------------------------
Ole Storm
The Institute of Applied Computer Science (IFAD)
Forskerparken 10, DK-5230 Odense M, Denmark
Phone: +45 6315 7134, Fax: +45 6593 2999, Email: storm@ifad.dk
WWW: http://www.ifad.dk
---------------------------------------------------------------