JVM堆内存溢出
堆內存溢出
配置參數
初始化,分配1M
最大內存,分配1M
代碼
package com.bjsxt.base001;public class Test02 {public static void main(String[] args) {byte[] b = null;// 連續向系統申請10MB空間for (int i = 0; i < 10; i++) {b = new byte[1 * 1024 * 1024];}} }程序分析
每次分配1M,循環10次
總共需要分配10M空間
運行
直接報錯OutOfMemoryError
總結