Results 1 to 9 of 9

Thread: a question about memory

  1. #1
    laotee is offline Registered User
    Join Date
    Jun 2005
    Posts
    41

    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.

  2. #2
    matthew's Avatar
    matthew is offline ZeroC Staff
    Name: Matthew Newhook
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Feb 2003
    Location
    NL, Canada
    Posts
    1,458
    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

  3. #3
    laotee is offline Registered User
    Join Date
    Jun 2005
    Posts
    41
    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.

  4. #4
    matthew's Avatar
    matthew is offline ZeroC Staff
    Name: Matthew Newhook
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Feb 2003
    Location
    NL, Canada
    Posts
    1,458
    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

  5. #5
    laotee is offline Registered User
    Join Date
    Jun 2005
    Posts
    41
    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.

  6. #6
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    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.

  7. #7
    laotee is offline Registered User
    Join Date
    Jun 2005
    Posts
    41
    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.

  8. #8
    matthew's Avatar
    matthew is offline ZeroC Staff
    Name: Matthew Newhook
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Feb 2003
    Location
    NL, Canada
    Posts
    1,458
    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

  9. #9
    laotee is offline Registered User
    Join Date
    Jun 2005
    Posts
    41
    Thank for you help.I know. 谢谢.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Out of Memory Error?
    By rnewport in forum Help Center
    Replies: 2
    Last Post: 05-14-2007, 09:38 AM
  2. A question about memory limit in Ice.
    By ehero in forum Help Center
    Replies: 3
    Last Post: 06-28-2005, 10:35 AM
  3. A question about decrease memory
    By laotee in forum Help Center
    Replies: 5
    Last Post: 06-27-2005, 05:25 AM
  4. Mismatched memory question
    By stephan in forum Help Center
    Replies: 6
    Last Post: 03-28-2005, 08:14 PM
  5. question about memory mgmt
    By Baloo in forum Help Center
    Replies: 2
    Last Post: 10-01-2004, 06:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •