17

This article describes how to view memory allocation stacktrace in Java VisualVM: http://rejeev.blogspot.de/2009/04/analyzing-memory-leak-in-java.html

In short, define a custom preset in the Java VisualVM options and check the "record allocations stack traces" checkbox in the memory settings tab.

Now, when I select that custom preset and start memory profiling, I still cannot view the memory allocation stacktrace. There is no right-click-on-item action "Take snapshot and show allocation stack traces" as described in the article, nor a anything like that. I am using VisualVM 1.7.

How can I view these allocation stack traces?

sina72
  • 4,931
  • 3
  • 35
  • 36
  • Where are you looking for that right click action 'Take snapshot and show allocation stack traces'? Did you select particular class in the live results table? – Tomas Hurka Aug 19 '12 at 09:18
  • Check that your JDK and JVM are compatible (for example, they are both 32-bit or both 64-bit). – Daniel Dec 25 '12 at 14:27

2 Answers2

22

If you can't see this option, go to Profiler -> activate "Settings" check box and activate "Record allocation stack traces" while the profiler is not active.

Peter Clause
  • 1,132
  • 9
  • 22
  • 4
    Also, while the profiler is running, you need to click the snapshot button, only then you can right click and view the allocation stack traces. – qwertzguy Nov 26 '14 at 19:01
2

Enable Memory profiling in Sampler tab, then press a Heap Dump button.

jkee
  • 693
  • 1
  • 6
  • 5
  • 11
    This is something different - heap dump does not show you allocation stack traces. In addition - to get the heap dump, you don't need to use 'Memory' profiling in'Sampler' tab. You can take a heap dump from 'Monitor' tab or from the context menu of the monitored application. – Tomas Hurka Aug 19 '12 at 09:11
  • Agreed this is an answer to a different question, although it's a useful approach. Eclipse Memory Analyzer is really helpful for analyzing heap dumps, but the VisualVM snapshot with allocation traces is really helpful independently. – adamfisk Sep 22 '13 at 20:10
  • Excuse the downvote: it was *accidental* (i must have clicked on it while trying to go to a different page)! There is a knee-jerk rule for SOF that after 5 mins your vote is locked in. Sorry about that! – WestCoastProjects Aug 30 '17 at 04:57
  • Besides that you can also take a look at the thread allocations then click on Deltas to see which thread is allocating more bytes (its more useful for multithreaded) – experiment unit 1998X Mar 03 '23 at 02:54