2 Replies Latest reply: Nov 28, 2007 4:02 AM by 843851 RSS

    Urgent - Memory management

    843851
      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)
      {
      try
      {
      int chkcnt=0;
      boolean comflag=true;
      System.out.println("Inside findPort");
      String Equipname="";
      Enumeration en=null;
      while(true)
      {
      en=null;
      en = CommPortIdentifier.getPortIdentifiers();
      if(en.hasMoreElements())
      {
      com = (CommPortIdentifier)en.nextElement();
      if (com.getPortType() == CommPortIdentifier.PORT_SERIAL)
      {
      System.out.println("Test"+com.getName());
      if(getEquipment())
      {
           System.out.println("COM port detected");
           return com;
      }
      else
           continue;
      }
      }
      }catch(Exception e)
      {
      e.printStackTrace();
      }
      }