分析内存时使用哪个 GC?
我使用 NetBeans 分析器(实际上是嵌入式 VisualVM)来监视 Java 应用程序的内存消耗。我使用堆视图、幸存代视图和内存转储来跟踪内存泄漏。
堆视图显示了已使用的内存总量,但由于垃圾收集器管理内存的方式,它有点混乱。该图本质上是锯齿形的,因此不太可读。有时,我会强制GC发生,这样我就可以获得更精确的实际内存消耗值。
我想知道:是否有一个垃圾收集器更适合内存分析,并且会产生更接近实际内存使用情况的堆图?或者更一般地说,我可以使用哪些 JVM 设置(-XX
选项或其他)来有效地跟踪内存泄漏?
I use the NetBeans profiler (which is actually an embedded VisualVM) to monitor the memory consumption of my Java applications. I use the heap view, the surviving generation view, and memory dumps to track memory leaks.
The heap view shows the total of used memory, but it's a bit chaotic, due to the way the garbage collector manages the memory. The graph is essentially sawtooth-shaped, and thus not particularly readable. Sometimes, I force the GC to happen, so that I can have a more precise value of the real memory consumption.
I was wondering : is there a garbage collector which is more appropriate for memory profiling, and which would yield a heap graph closer to the real memory usage ? Or more generally, what JVM settings (-XX
options or other) can I use in order to efficiently track memory leaks ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在图表中看到的是应用程序内存利用率的真实行为。重复的锯齿模式可能是由于分配了正在清除的短寿命对象。如果您认为存在内存泄漏,请拍摄堆转储快照并查看堆中保留了哪些对象。您可以使用 JConsole 拍摄快照,并使用 HPjmeter。
What you are seeing in your graph is the real behavior of your applications memory utilization. The repeated sawtooth pattern is likely due to allocations of short lived objects which are being scavenged. If you believe you have a memory leak, take a heap dump snapshot and see what objects are being retained in the heap. You can take a snapshot using JConsole and open the resulting dumpfile using HPjmeter.
我建议您使用您打算使用的 GC,而不使用分析器。使用这种方法,您将获得一个更像应用程序行为方式的图表,尽管并不总是那么可读。
如果您想要一个更具可读性但又不那么真实的图表,您可以将最小内存大小增加到 1 GB。这将导致更少的 GC 和更少的尖峰图形,但除了使图形更漂亮之外可能没有任何帮助。
I suggest you use the GC you intend to use without the profiler. Using this approach you will get a graph which is more like how the application will behave, though not always as readable.
If you want a graph which is more readable, but not as realistic, you can increase the minimum memory size to say 1 GB. This will result in less GCs and a less spikey graph but may not help you except make the graph prettier.