测试代码:
java
public class TestHeapDumper {工具
//该属性也从Heap上new出来测试
public Integer testInt= new Integer(1);spa
//测试方法对象
public static void main(String args[]) throws InterruptedException{ip
System.out.println("yes");文档
//在Heap堆上,new一个对象出来get
TestHeapDumper testHeapDumper = new TestHeapDumper();it
//程序等待,不要退出io
Thread.sleep(1000000L);
//这里再次使用到testHeapDumper,防止GC掉;
System.out.println(testHeapDumper.testInt);
}
}
、
p0为dump文件的路径,后缀名为.hprof
而后再Memory Analyser工具中打开
能够发如今TestHeapDumper实例中,有TestInt变量。
若是把testInt申明为:
//测试是否可以在Heap堆上分配
public int testInt= 1;
能够发现并无在Heap上分配。
Memory Analyser工具用起来很不错,能够经过outgoing reference 和incoming refence 引用来找到相互引用,如一张网; shallow Heap,Retained Heap表示对象本身大小和包括引用迭代出来的大小。具体能够参见 Eclipse Memory Analyser帮助文档
参见:http://www.ibm.com/developerworks/cn/java/j-lo-langref/
有对StrongReference, SoftReference, WeakReference 以及 PhantomReference 的特性及用法
的讲解。