Home Help Center

a question about memory

laoteelaotee Member ✭✭
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

  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    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
  • laoteelaotee Member ✭✭
    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.
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    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
  • laoteelaotee Member ✭✭
    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.
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    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.
  • laoteelaotee Member ✭✭
    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.
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    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
  • laoteelaotee Member ✭✭
    Thank for you help.I know. :) 谢谢.
Sign In or Register to comment.