Java堆和堆栈内存分配 [英] Java heap and stack memory allocation
本文介绍了Java堆和堆栈内存分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class Person{
private String name;
public Person(){
}
public Person(String name){
this.name=name;
}
public static void main(String[] arg)
{
Person per= new Person("Andy");
}
}
每
是一个局部变量,它将被存储在堆还是堆栈中?
per
is a local variable, where will it be stored, on the heap or the stack?
推荐答案
在堆上。每次使用 new
创建对象时,都会在堆上分配它。
On the heap. Any time you use new
to create an object, it is allocated on the heap.
这篇关于Java堆和堆栈内存分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文