Search code examples
javaheap-dump

How do I inspect specifically what Java strings are being kept around, causing memory leak?


I can see in the heapdump file that the String class exhausted memory, but how do I know specifically what those strings are?


Solution

  • If you use VisualVM you can use couple of OQL query to read the data in Java heap that you are looking for. One command that may suit your need is:

     select {instance: s, content: s.toString()} from java.lang.String s
        where /java/(s.toString())
    

    you can find a lot more here: https://visualvm.github.io/documentation.html, section Analyzing a Heap Dump Using OQL