Java深入---Java堆溢出以及垃圾回收机制
2015-05-28 10:15
603 查看
</pre><pre name="code" class="java">import java.util.ArrayList; import java.util.List; /** * @author MohnSnow * @time 2015年5月27日 下午5:39:17 * */ /* * 测试Java堆溢出 * * JVM-SET: -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails * -XX:SurvivorRatio=8 * OOM: OutOfMemoryError */ public class Test { static class OOMObject { static { System.out.println("test;"); } } public static void main(String[] args) { List<OOMObject> list = new ArrayList<OOMObject>(); while (true) { list.add(new OOMObject()); } } }
/** * @author MohnSnow * @time 2015年5月28日 上午10:39:17 * */ /* * 垃圾回收机制中的引用记数算法:给对象添加一个引用计数器,每当一个地方引用他时,计数器就加一;当引用失效时候,就减一;任何时刻计数器为零的对象,就是不可能在被使用的 * 。 */ public class Test { public Object instance = null; private static final int _1MB = 1024 * 1024; public byte[] bigSize = new byte[2 * _1MB]; public static void testGC() { Test objA = new Test(); Test objB = new Test(); objA.instance = objB; objB.instance = objA; objA = null; objB = null; System.gc(); } public static void main(String[] args) { testGC(); } }
相关文章推荐
- 深入理解Java垃圾回收机制以及内存泄漏
- 深入理解java垃圾回收机制----
- 深入理解Java垃圾回收机制
- Java垃圾回收机制以及内存泄露
- 深入理解 Java 垃圾回收机制
- Java内存区域分配、存储、垃圾回收策略与回收机制(深入JVM虚拟机)
- 深入理解java垃圾回收机制----
- 深入理解 Java 垃圾回收机制
- 深入理解 Java 垃圾回收机制
- 深入理解 Java 垃圾回收机制
- 深入理解Java垃圾回收机制
- Java垃圾回收机制以及内存泄露
- Java垃圾回收机制以及内存泄漏
- 深入理解 Java 垃圾回收机制
- 深入理解 Java 垃圾回收机制
- 深入理解 Java 垃圾回收机制
- Java 垃圾回收机制(以及怎么减少调用GC,提高性能)
- 转载 深入Java核心 探秘Java垃圾回收机制
- 深入理解 Java 垃圾回收机制
- 深入理解 Java 垃圾回收机制