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.