I have Java application, which, unfortunately, begins to consume quite big amounts of memory after some time. To complicate things, it's not only Java application, it is also JavaFX 2 application.
I suspect that there is some memory leak, maybe even in underlying JavaFX calls and native libs.
The ideal solution would be to get a dump of all java objects at some moment (with their memory usage), and then analyze that dump. Is there some way to achieve this?
There are lots of ways to get a heap dump, starting with simple tools like jmap to more fancy stuff like JVisualVM or even commerical tools as JProfiler. Correctly interpreting those dumps can be tricky though, so you might want to post exactly what you are looking for. Are going hunting for a memory leak, or are you interested in getting a general feel for your application?
I just re-discovered this article when researching ways to grab "JVM state right at this moment" - after a heap I pulled with
jmap
was about half the size of what the MBeans reported. I'll add it for completeness:Requires gdb installed (for
gcore
) and a JDK installation (for jmap). Also note you'd might need to adjust/usr/bin/java
to the path of the JVM used for the process.You can use jvisualvm. It has plugin to see live memory and get a dump out of it.
Use
jmap -heap:format=b <process-id>
to create a binary dump of the heap which can then be loaded into several tools - my favorite being the "Eclipse Memory Analyzer"