/Users/lyon/j4p/src/serialPorts/OpenCloseTest.java

1    package serialPorts; 
2     
3    /* 
4    open() can leak memory in some CommAPI implementations 
5              when called multiple times. 
6    */ 
7     
8    import gnu.io.CommPortIdentifier; 
9    import gnu.io.SerialPort; 
10    
11   public class OpenCloseTest { 
12       public static void main(String args[]) { 
13           CommPortIdentifier portId; 
14           SerialPort serialPort; 
15    
16           int i = 0; 
17           while (true) { 
18               try { 
19                   System.out.println("i=" + i++); 
20                   portId = CommPortIdentifier.getPortIdentifier( 
21                           "cu.modem" 
22                   ); 
23                   serialPort = (SerialPort) portId.open( 
24                           "cu.modem", 200 
25                   ); 
26                   serialPort.close(); 
27                   System.out.println("done"); 
28               } catch (Exception ie) { 
29               } 
30           } 
31       } 
32   } 
33    
34