JVM(10)--stackoverflow实战
2016-04-16 10:40
197 查看
HeapOutOfMemory
堆溢出 情况多见于对象过多,存在多余引用,使对象未及时释放public class Miao { public static void main(String[] args) throws Exception{ ArrayList<String> strs = new ArrayList<>(10000_0000); for(int i = 0 ;i <= 10000_0000; ++ i){ strs.add(Integer.toString(i)); if(i % 10000 == 0){ System.out.println(i); } } } }
Young OutOfMemory
设置XX:MaxTenuringThreshold为一个很大的值使对象无法及时的移动到年老代中,导致年轻代内存溢出
MethodArea OutOfMemory
在经常动态生成大量Class的应用中,需要特别注意类的回收状况。这类场景除了上面提到的程序使用了CGLib字节码增强和动态语言之外,常见的还有:大量JSP或动态产生JSP文件的应用(JSP第一次运行时需要编译为Java类)、基于OSGi的应用(即使是同一个类文件,被不同的加载器加载也会视为不同的类)等。ConstantPool OutOfMemory
一般来说是不可能的,只有项目启动方法区内存很小或者项目中的静态变量极其多时才会发生DirectMemory OutOfMemory
堆外内存溢出 一般与nio有关public class Miao { public static void main(String[] args) throws Exception{ List<ByteBuffer> buffers = new ArrayList<>(); while(true){ ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024 * 1024); buffers.add(buffer); } } }
Stack OutOfMemory Stack OverFlow
栈溢出 一般与方法递归次数过多或者方法中有产生大量数据的循环有关public class Miao { public static void main(String[] args) throws Exception{ new Miao().miao(); } public void miao(){ long time = System.currentTimeMillis(); miao(); } }
相关文章推荐
- ssl2340 格子游戏
- Android源码编译整理总结
- 监听ContentProvider内容改变
- jQuery 获取元素并添加
- LeetCode——020
- 1007 Cable master
- HDU 2089 不要62(数位DP·记忆化搜索)
- iOS中宏定义的使用与规范
- quartz CronExpression表达式
- 51nod 1419 最小公倍数挑战
- Android studio如何使用SVN进行版本控制?
- Android studio - SVN 使用教程
- linux忘记root密码
- SAP中寄售处理
- c++ 宏的使用
- X210板载gsensor介绍
- 'lower_case_table_names'错误解决方法
- C#进行Redis操作
- 【金融支付】名词:支付账户、备付金、网络支付、银行卡清算、贷记卡、代扣、代付
- 《网络工程师》 Part5 无线通信网