简体   繁体   English

如何调试JAVA Heap中的内存不足错误

[英]How to debug Out of memory error in JAVA Heap

I am not able to debug the issue ,what are the possibilities it can happen. 我无法调试该问题,可能会发生什么情况。 Can anyone tell me ? 谁能告诉我?

There are some tools available for memory profiling. 有一些可用于内存分析的工具。

1) Eclipse Memory Analyzer (MAT) 1)Eclipse内存分析器(MAT)

2 ) Java VisualVM 2Java VisualVM

See the reports generated through tools and fix the issue mention in memory profiling reports. 查看通过工具生成的报告,并修复内存概要分析报告中提到的问题。

You can use any one of them to generate report 您可以使用其中任何一个来生成报告

The simple way - you can use jvisualvm from JDK. 简单的方法-您可以使用JDK中的jvisualvm。 In left side select your application, and then perform heap dump on Monitoring tab, then you can found memory leak. 在左侧选择您的应用程序,然后在“监视”选项卡上执行堆转储,然后您会发现内存泄漏。 Also you can run memory profiler in jvisualvm. 您也可以在jvisualvm中运行内存事件探查器。

Use command line 'breakpoints'. 使用命令行“断点”。 A few lines in, add something like 在几行中添加类似

System.out.println("Made it thus far!");

or in code with lots of loops, you can use this to make sure that you don't iterate too many times: 或在具有大量循环的代码中,可以使用此方法来确保不会重复太多:

System.out.println("Made it thus far! i = " + i1); where i1 is an additional loop counter. 其中i1是一个附加的循环计数器。

and move it down and down until you get your error instead of that print. 然后上下移动它,直到出现错误而不是该打印错误为止。 This will help determine the line at which the error is occurring. 这将有助于确定发生错误的行。

Please remember to post your code if you can as it makes the job a whole lot easier and you can have your problem solved in under a minute. 请记住,如果可以的话,请发布代码,因为这会使工作变得更加轻松,并且一分钟之内即可解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM