准确的说应该是java8以前的内存管理方式
区别在永久代(方法区)上
public class RamManager {//1.a存储于永久代public static int a =1;private String str;private int x;private AA aaa;
// method_1方法位于栈中// temp1保存的是引用地址,在栈中public void method_1(String temp1) {// temp1将引用地址赋给this.str,this引用在栈中,this实例在堆中,this.str也在堆中,保存了temp1的值,为字符串"aaa"的地址this.str = temp1;// this.x在堆中this.x = 1;// b在栈中int b = 2;// attr变量在栈中,new int实例在堆中int[] attr = new int[10];attr[0] = 1;// aa变量在栈中,实例AA在堆中AA aa = new AA();// this.aaa在堆中,保存了aa变量的地址this.aaa = aa;}// main方法位于栈中public static void main(String[] args) throws Exception{// ramManager变量在栈中创建,new Manager实例在堆中创建RamManager ramManager = new RamManager();// string变量在栈中,保存的"aaa"的地址,"aaa"在常量池中String string = "aaa";ramManager.method_1(string);}