Java:找出什么正在使用所有内存
我有一个 Java 应用程序内存不足,但我不知道哪个代码正在分配内存。有没有一个应用程序可以让我检查这个?我使用Eclipse。
I have a java application that runs out of memory, but I have no idea which code is allocating the memory. Is there an application with which I can check this? I use Eclipse.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
由于您使用 eclipse,我建议您使用 Eclipse Memory Analyzer 插件。这个工具效果很好,甚至可以提供一份包含一些可能的泄漏嫌疑人的报告。我已经查看了超过 1G 的堆转储,没有任何问题。我只是使用 JDK 附带的 jconsole 来获取转储。
另外,这里还有一篇关于使用该工具的精彩博客,作者是该工具的一位作者。
这也是免费的。
Since you use eclipse I would recommend the Eclipse Memory Analyzer plugin. This tool works great, and will even provide a report with some likely leak suspects. I have looked at over 1G heap dumps with this with no problems. I just use jconsole included with the JDK to get the dump.
Also here is a great blog on using the tool, by one of the authors of the tool.
This is also free.
VisualVM 是一个集成了多个命令行 JDK 工具和轻量级分析功能的可视化工具。它专为生产和开发时使用而设计,进一步增强了 Java SE 平台的监控和性能分析能力。
并且它包含在JDK中。
VisualVM is a visual tool integrating several commandline JDK tools and lightweight profiling capabilities. Designed for both production and development time use, it further enhances the capability of monitoring and performance analysis for the Java SE platform.
And it is included in JDK.
方面取得了巨大成功
我在 JProfiler http://www.ej-technologies 。 com/products/jprofiler/overview.html
I've had great success with JProfiler
http://www.ej-technologies.com/products/jprofiler/overview.html
您需要一个分析器。
这是一个完整的列表。
You want a Profiler.
Here is a comprehensive list.
您需要使用内存分析器。您可以使用 Sun 的 JVM 工具接口或第三方分析器,例如 JProfiler。 Eclipse 还具有分析工具,称为 Test &性能工具平台 (TPTP)。
You need to use a memory profiler. You can either use Sun's JVM Tool Interface or a third-party profiler like JProfiler. Eclipse also has profiling tools, called the Test & Performance Tools Platform (TPTP).
我确信每个人都有自己喜欢的,但我推荐 Netbeans。
I'm sure everyone has their favorite, but I recommend Netbeans.
Yourkit 是一个很棒的工具,我曾在很多场合使用它来查找和记录性能问题。带有 TPTP 框架的 Eclipse 也可用于执行此操作。它也适用于远程应用程序服务器(您需要启用分析代理并在 JVM 中打开远程调试),但它允许您针对几乎任何 J2EE 环境运行分析。
Yourkit is a great tool that I've used on MANY occasions to find and document performance issues. Eclipse with the TPTP framework can be used to do this as well. It also works well against remote application servers (you need to enable profiling agents and turn on remote debugging in the JVM), but it lets you run profiling against pretty much any J2EE environment.
为了快速分析或者如果您不使用 Eclipse 或旧版本的 jvm, hprof 是一个不错的选择。 (我只是添加它作为参考。)。
For fast profiling or if you don't use Eclipse or older versions of the jvm, hprof is a decent alternative. (I just add that as a reference.).
前几天我必须找到产生 2.6G 堆转储的内存泄漏的根源。 Jhat 需要令人难以置信的 20G 堆大小才能在不崩溃的情况下处理它。 Eclipse 内存分析器在 10G 以下完成了这项工作。也就是说,我发现这两种工具都很有用,但首先会推荐内存分析器,以便更有效地使用内存并且更易于使用。
我对所使用的内存量感到非常惊讶,但我可以向您保证,如果我使用的内存量较少,我就会出现 OutOfMemory 错误。
I had to find the source of a memory leak that produced a 2.6G heap dump the other day. Jhat required an unbelievable 20G heap size to crunch through it without crashing. Eclipse memory analyzer did it in under 10G. That said, I found both tools useful, but would recommend memory analyzer first for more efficient use of memory and being more easy to use.
I was pretty amazed by the amount of memory used but I can assure you if I used less I head OutOfMemory errors.
我使用 HP Diagnostics Profiler 免费评估(5 个线程无限制)。它允许以直观、简单的方式跟踪内存分配并进行堆分析。
I've spotted memory leaks using HP Diagnostics Profiler free evaluation (unlimited for 5 threads). It allows to trace memory allocation and do heap analysis in a visual, easy way.