2 Replies Latest reply on Nov 28, 2007 10:02 AM by 843851

    Urgent - Memory management

      Hi all,

      I am developing an application to interface with a device connected to a COM port. I use JAVA COMM api for the connectivity. I am enumerating the ports available in JAVA using CommPortIdentifier.getPortIdentifiers() method which is static and returns the port available in the system. I am searching for the connectivity of my device through the COM ports available in the system. Whenever the program finds a port connected to the device the searching operation will stops. But till it find the device the loop will continously search for the device at the background using the CommPortIdentifier.getPortIdentifiers().

      The problem I am having is JAVA memory is increasing gradually for each cycle of detection. If I run my program at the background without connecting a device for six hours it occupies 120 MB of memory. Please help us how to avoid this memory usage.

      Below is the code snippet :

      static CommPortIdentifier com=null;
      private CommPortIdentifier findPort(String name)
      int chkcnt=0;
      boolean comflag=true;
      System.out.println("Inside findPort");
      String Equipname="";
      Enumeration en=null;
      en = CommPortIdentifier.getPortIdentifiers();
      com = (CommPortIdentifier)en.nextElement();
      if (com.getPortType() == CommPortIdentifier.PORT_SERIAL)
           System.out.println("COM port detected");
           return com;
      }catch(Exception e)