RLK.AWTRLK (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.AWT warning indicates that an AWT object is not disposed 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 112 public void deleteAll(File[] files) { 13 for (final File file : files) { 14 ConfirmDialog confirmDialog = new ConfirmDialog(file); 15 confirmDialog.setVisible(true); 16 if (confirmDialog.isConfimed()) { 17 file.delete(); 18 } 19 } 20 } RLK.AWT is reported for the snippet on line 14: dialog 'confirmDialog' is not disposed after creation. Example 212 public void deleteAll(File[] files) { 13 for (final File file : files) { 14 ConfirmDialog confirmDialog = new ConfirmDialog(file); 15 try { 16 confirmDialog.setVisible(true); 17 if (confirmDialog.isConfimed()) { 18 file.delete(); 19 } 20 } finally { 21 confirmDialog.dispose(); 22 } 23 } The snippet from the previous section is fixed; RLK.AWT is not reported here. ExtensionThis checker can be extended through the Klocwork knowledge base. See Tuning Java analysis for more information. |