Archived

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

a question about memory

for(int i=0;i<100;i++)
{
try
{
o_icecomm = Ice.Util.initialize(ref arg);

Ice.ObjectPrx obj = o_icecomm.stringToProxy("PCManager:default -h 172.16.166.6 -p 10000");
PCManagerPrx PCmanager= PCManagerPrxHelper.checkedCast(obj);
..........
}
catch
{

}
}

when the program is executed, throw exceptions.because I did not start service of ICE. I find that memoy of thread grow fastly.why?

thank you.

Comments

  • matthew
    matthew NL, Canada
    Are you destroying the communicator? If not, you should. its not clear why you'd want to create a communicator over & over again. What do you hope to achieve by doing this?

    Regards, Matthew
  • for example: I Input a IP of server,but if the server is not open ,connection will not be created. PCManager will be created
    continuously ,but the creation is not successful every time , memory group continuously.my purpose is to connect the server realtime.
  • matthew
    matthew NL, Canada
    You only need to create the communicator once, not over & over again. The problem in your application most likely is that you do not call destroy() on the communicator, so the resources are never released.

    Matthew
  • I call destroy() ;

    for(int i=0;i<100;i++)
    {
    try
    {
    o_icecomm = Ice.Util.initialize(ref arg);

    Ice.ObjectPrx obj = o_icecomm.stringToProxy("PCManager:default -h 172.16.166.6 -p 10000");
    PCManagerPrx PCmanager= PCManagerPrxHelper.checkedCast(obj);
    ..........
    }
    catch
    {
    o_icecomm = Ice.Util.initialize(ref arg);/////////////////////////////////
    Ice.ObjectPrx obj = o_icecomm.stringToProxy("PCManager:default -h 172.16.166.6 -p 10000");

    PCManagerPrx PCmanager= PCManagerPrxHelper.uncheckedCast(obj);
    o_icecomm.destroy();

    }
    }


    but,the resources are not released.
  • marc
    marc Florida
    I don't see destroy being called for the communicator in the try-block. You apparently create a new communicator in the catch-block (why?), which then gets destroyed, but only if the catch-block itself doesn't raise an exception.

    Please have a look at one of the Ice demos and the Ice manual for more information on how to properly initialize and shut down communicators.
  • Because I only destroy the communicator that was not connect.

    If it throws exception in "PCManagerPrx PCmanager= PCManagerPrxHelper.checkedCast(obj);" . I only want to destroy the communicator in "Ice.ObjectPrx obj = o_icecomm.stringToProxy("PCManager:default -h 172.16.166.6 -p 10000");". If it does'n throws exception,I shall create communicator and connect. So I destroy communicator in Catch-block.
  • matthew
    matthew NL, Canada
    I don't understand what you are trying to say. But the sample code you pasted is not correct. It should read something like:

    o_icecomm = Ice.Util.initialize(ref arg);

    for(int i=0;i<100;i++)
    {
    try
    {
    Ice.ObjectPrx obj = o_icecomm.stringToProxy("PCManager:default -h 172.16.166.6 -p 10000");
    PCManagerPrx PCmanager= PCManagerPrxHelper.checkedCast(obj);
    ..........
    }
    catch
    {
    Ice.ObjectPrx obj = o_icecomm.stringToProxy("PCManager:default -h 172.16.166.6 -p 10000");

    PCManagerPrx PCmanager= PCManagerPrxHelper.uncheckedCast(obj);

    }
    }

    o_icecomm.destroy();

    You should not create the communicator over and over again.

    Matthew
  • Thank for you help.I know. :) 谢谢.