//演示内存溢出
import java.util.*;
class OOMDemo
{
static class OOMObject{}
public static void main(String[] args)
{
List<OOMObject> list = new ArrayList<OOMObject>();
while(true)
{
list.add(new OOMObject());
}
}
}
/*结果:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.ensureCapacity(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
at OOMDemo.main(OOMDemo.java:10)
*/
内存溢出(1)
最新推荐文章于 2024-08-12 16:40:29 发布