Java中的堆(Heap)是一个运行时数据区,用来存放类的对象:栈(Stack)主要存放基本的数据类型(int.char.double等8种基本数据类型)和对象句柄. 例1 int a=5; int b=5; System.out.println(a==b); 以上例子中,编译器首先处理int a=5,首先在栈中创建一个引用a,然后在栈中查找是否有5这个值,如果有,则将a指向5,如果没有,则创建一个5,再将a指向5.当处理int b=5时,由于栈中肯定已经存在5,直接将b指向5,这样a和b都指向…
在Java代码中,常常会使用到这样的类的声明实例化: Person per = new Person(); //这其实是包含了两个步骤,声明和实例化 Person per = null; //声明一个名为Person类的对象per per = new Person(); // 实例化这个per对象 声明 指的是创建类的对象的过程: 实例化 指的是用关键词new来开辟内存空间. 它们在内存中的划分是这样的: 那什么是栈内存(heap)和栈内存(heap)呢? 栈内存: 在函数中定义的一些基本类型的…
BSS, block start segment, static memory, to store the global data which are not initialized. DATA, data segment, static memory, to store the global initialized variables. TEXT, code segment to store the program code. HEAP, dynamic memory segment to s…