通常 List list = new ArrayList(); while (true) { list.add(....); } 导致OOMEvoid x() { x(); } 导致SOE
OutOfMemoryException jvm占用的内存不够了StackOverFlowError 方法的stack溢出 比如不停的方法掉方法没有出口 class A{ A(){ new A(); } public static void main(String[] arg){ new A(); } }
OutOfMemoryException 一般是由死循环引起的
前者是内存溢出。 后者是jvm栈溢出。
class A{ A(){ new A(); } public static void main(String[] arg){ new A(); } }这样为什么会爆掉堆栈呢?所有new出来的对象不是放在堆中吗?我觉得应该爆掉堆啊,所以应该是OutOfMemoryException,还请高手指教。
List list = new ArrayList();
while (true) {
list.add(....);
}
导致OOMEvoid x() {
x();
}
导致SOE
class A{
A(){
new A();
}
public static void main(String[] arg){
new A();
}
}
后者是jvm栈溢出。
A(){
new A();
}
public static void main(String[] arg){
new A();
}
}这样为什么会爆掉堆栈呢?所有new出来的对象不是放在堆中吗?我觉得应该爆掉堆啊,所以应该是OutOfMemoryException,还请高手指教。
说了没有
说了没有
说了没有
你不听吗
(丢一支笔)
stack 一般是方法调用地址存放区
比如 a.method(b.method(c.method))一共会保存3个方法调用地址
如果方法调用死循环了 存放方法地址的stack就overflow了