Search code examples
javaperformancememory-leaksinputstreamfilereader

How to find the Java resource leaks if the file/connection resources are not being closed at runtime.?


  1. Is it possible to find the Unclosed resource streams in code at runtime?
  2. Is there any tool or any method to find if any file/connection resources are leaking and are not closed properly by the developer. I want to know this at runtime of the program with Heap Dump or any other method available. Please let me know if you know any tools or library available.

Thanks.


Solution

  • Some profilers offer the capability to detect resource leaks. In JProfiler, for example, there is a "Files" probe that shows you which files are still open

    enter image description here

    The same functionality is available for sockets and processes.

    Another common source of resource leaks are JDBC connections which are handled by the JDB probe:

    enter image description here

    Disclaimer: My company develops JProfiler.