Making a “memory dump” of java application?

2019-01-25 07:24发布

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?

4条回答
我只想做你的唯一
2楼-- · 2019-01-25 07:30

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?

查看更多
Explosion°爆炸
3楼-- · 2019-01-25 07:33

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:

su $JVM_OWNER -c "gcore -o /tmp/jvm.core $YOUR_JVM_PID"
su $JVM_OWNER -c "jmap -dump:format=b,file=jvm.hprof /usr/bin/java /tmp/jvm.core"

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.

查看更多
Juvenile、少年°
4楼-- · 2019-01-25 07:41

You can use jvisualvm. It has plugin to see live memory and get a dump out of it.

查看更多
ら.Afraid
5楼-- · 2019-01-25 07:55

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"

查看更多
登录 后发表回答