首页 > 编程语言 > 详细

OOM内存溢出java代码实例1

时间:2019-09-24 09:03:10      阅读:100      评论:0      收藏:0      [点我收藏+]

代码如下:

 1 package com.github.mayangbo666.test;
 2 
 3 import java.util.ArrayList;
 4 import java.util.List;
 5 
 6 public class OOM1 {
 7     public static void main(String[] args) {
 8         List<Byte[]> list = new ArrayList<>();
 9         int i = 0;
10         try {
11             while (true) {
12                 list.add(new Byte[1024 * 1024]);//每次1M
13                 i++;
14             }
15         } catch (Throwable throwable) {
16             throwable.printStackTrace();
17             System.out.println("次数: " + i);
18         }
19     }
20 }

执行结果图:

技术分享图片

 堆(heap)与栈(stack)

可以看到这里是堆内存溢出

其实也有栈内存溢出

 ...

 

OOM内存溢出java代码实例1

原文:https://www.cnblogs.com/m-yb/p/11576006.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!