1 .堆栈溢出堆栈溢出错误堆栈是线程专用的,生命周期与线程相同,每个方法在运行时都包含本地变量表、操作数堆栈、动态链接和方法出口等信息
栈溢出:执行方法时创建的堆栈帧数超过了堆栈深度。
原因举例:方法递归
【例】:
publicclassstackerror {私有Inti=0; public void fn () system.out.println ) ) I; fn (); } publicstaticvoidmain (string [ ] args ) stackerrorstackerror=newstackerror ); 堆栈错误. fn (; }【输出】:
33558 www.Sina.com/:调整JVM堆栈大小:-Xss
http://www.Sina.com/http://www.Sina.com /
setsthethreadstacksize(inbytes ).appendtheletterkorktoindicatekb,m or M to indicate MB,andgorgtoindicategb.thedefaultvaltvalute
Linux/x64 (64位) :1024 kbm acos (64位) :1024 kboraclesolaris/x64 (64位) ) ) )。 33601024 kb windows : thedefaultvaluedependsonvirtualmemorythefollowingexamplessetthethreadstacksizeto 1024 kbindifferentunits 34
-Xss1m
-Xss1024k
-Xss1048576
thisoptionissimilarto-xx :热堆叠大小。
在IDEA中点击Run菜单的Edit Configuration,如下图所示。
设定后,再次运行时,I的值变小。 这是因为设置的-Xss值小于原始值。
2 .对象主要存储在堆栈溢出内存错误3360 javaheapspace堆中。
3358www.Sina.com/:new对象随后会充满堆中的空间。 如果虚拟机堆栈内存允许动态扩展,则当扩展堆栈容量无法请求足够的内存时。
【例】:
publicclassheaperror { publicstaticvoidmain (字符串[ ] args ) { ListString list=new ArrayList ); try{while(true ) list.add ) ) Floweryu ); }catch(throwablee ) system.out.println ) list.size ); e .打印堆栈跟踪(; ()【输出】:
解决方法:调整堆大小: Xmx
http://www.Sina.com/http://www.Sina.com /
特殊字节(在字节中)。 ofthememoryallocationpoolinbytes.thisvaluemustbeamultipleof 1024 andgreaterthan 2mb.appendtheletterkorktoindicatekilobytes,) andgorgtoindicategigabytes.thedefaultvalueischosenatruntimebasedonsystemconfiguration.forserverdeployments, - xmsand-xmxareoftensettothesamevalue.thefollowingexamplesshowtosetthemaximumallowedsizeofallocatedmemoryto 80 mbyusingvvvv
-Xmx83886080
-Xmx81920k
-Xmx80m
the-xmxoptionisequivalentto-xx : max heapsize。
安装-Xmx256M后,输入以下内容,使其小于以前的值: