RLK.MICRORLK (Resource Leak) issues are reported when resources are allocated but not properly disposed after use. Failing to properly dispose a resource can lead to such problems as:
An RLK.MICRO warning indicates that a JavaME connection is not closed on exit. Vulnerability and riskResources such as streams, connections and graphic objects must be explicitly closed. The close operation can unblock transactions or flush file changes in the file system. While a resource will eventually be closed by the garbage collector, resource exhaustion can occur before garbage collection starts. Depending on the nature of the resource, various exceptions will be thrown on a failed attempt to allocate another resource, for example: java.io.FileNotFoundException: Too many open files or too many database connections. Mitigation and preventionExplicitly close all resources that have the close method, even those that you think are not doing anything significant. Future code changes will then be safe from such errors. Example 120 public byte[] getData(final String url) throws IOException { 21 ContentConnection connection = (ContentConnection) Connector.open(url); // Resource allocated 22 InputStream iStrm = connection.openInputStream(); 23 int length = (int) connection.getLength(); 24 if (length > 0) { 25 byte data[] = new byte[length]; 26 iStrm.read(data); 27 return data; 28 } 29 return EMPTY; 30 } RLK.MICRO is reported for the snippet on line 21: 'connection' is not closed on exit. Example 220 public byte[] getData(final String url) throws IOException { 21 ContentConnection connection = (ContentConnection) Connector.open(url); // Resource allocated 22 try { 23 InputStream iStrm = connection.openInputStream(); 24 int length = (int) connection.getLength(); 25 if (length > 0) { 26 byte data[] = new byte[length]; 27 iStrm.read(data); 28 return data; 29 } 30 return EMPTY; 31 } finally { 32 connection.close(); // Resource released 33 } 34 } The snippet from the previous section is fixed; RLK.MICRO is not reported here. ExtensionThis checker can be extended through the Klocwork knowledge base. See Tuning Java analysis for more information. |