I can see in the heapdump file that the String class exhausted memory, but how do I know specifically what those strings are?
2 Answers
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

- 9,678
- 13
- 71
- 102

- 6,083
- 3
- 23
- 43
-
That looks useful! Can I ask a dumber question, where do I execute this query? Is there a console builtin to JVisualVm or something? – One Two Three Mar 31 '16 at 20:40
-
@OneTwoThree: there is both command line and visual tools, you can see the full documentation on their website. it is a very useful tool – Pooya Mar 31 '16 at 20:43
I simulated this with a small Spring Boot application and Eclipse Memory Analyzer. The heap dump was created from inside MAT but you could also open the heap dump you already created.
When you open the heap dump MAT automatically shows you suspects which are using a lot of memory:
When you open the details you can see the String
instances and their values (marked in yellow in my screenshot) in the section called Accumulated Objects in Dominator Tree
Short note: you can run OQL from within MAT too:

- 9,678
- 13
- 71
- 102

- 10,577
- 10
- 57
- 99