java内存数据管理

准确的说应该是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); }

 

posted @ 2016-02-24 16:21  小N~  阅读(141)  评论(0编辑  收藏  举报