首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > PowerDesigner >

HeapDumpOnOutOfMemoryError堆转储实践跟一些分析

2013-08-01 
HeapDumpOnOutOfMemoryError堆转储实践和一些分析public static void main(String[] args) {long arr[]fo

HeapDumpOnOutOfMemoryError堆转储实践和一些分析
public static void main(String[] args) { long arr[]; for (int i=1; i<=10000000; i*=2) { arr = new long[i]; }}

public static void main(String[] args){ for (int i = 1; i <= 10000000; i *= 2) { long[] arr = new long[i]; }}

System.out.println("size : " + i);Runtime runtime = Runtime.getRuntime();System.out.printf("maxMemory : %.2fM\n", runtime.maxMemory()*1.0/1024/1024);System.out.printf("totalMemory : %.2fM\n", runtime.totalMemory()*1.0/1024/1024);System.out.printf("freeMemory : %.2fM\n", runtime.freeMemory()*1.0/1024/1024);

public static void main(String[] args) { long arr[] = {}; for (int i=1; i<=10000000; i*=2) { arr = new long[i]; }}

public static void main(String[] args){ long[] arr = new long[0]; for (int i = 1; i <= 10000000; i *= 2) { arr = new long[i]; }}


?

小结:通过分析OutOfMemoryError时生成的堆转储文件,有助于找到内存不够用的原因;如果生成的堆转储文件的大小跟最大堆内存的配置有很大差异,就要分析抛出异常的代码,查找原因,还可以将字节码反编译,看看编译器是不是对代码的结构进行了调整。

热点排行