Java記憶體分析

來源:互聯網
上載者:User

標籤:java   記憶體分析   

在Java中,記憶體的管理分為: Stack(棧), Heap(堆), DataSegment(資料區段), CodeSegment(程式碼片段)

Stack(棧): 基礎資料型別 (Elementary Data Type)(byte,short,int,long,char,float,double,boolean), 局部變數, 對象的引用地址

Heap(堆): 存放對象執行個體,new出來的東西放這裡
DataSegment(資料區段): 靜態變數和字串常量

CodeSegment(程式碼片段): 顧名思義存放代碼

650) this.width=650;" width="547" height="338" title="記憶體分析圖" style="width:468px;height:251px;float:left;" alt="wKioL1XUL-ODQNiNAALOjEBpj_4167.jpg" src="http://s3.51cto.com/wyfs02/M01/71/95/wKioL1XUL-ODQNiNAALOjEBpj_4167.jpg" />










執行個體:

下面通過分析一個例子來說明java變數是怎麼存放在記憶體中的

Code segment:arraylistlist[]=new arraylist[2];

Arraylist[0]=2;arraylist[1]=3;arraylist[2]=4;

因為list[]是一個變數,這是一個聲明我們放到棧中。

而後面每個數組執行個體化出來的變數,所以放到堆中。

而實實在在存在的變數的值都是常量,所以放在常量池中,也就是中的datasegment。


Java記憶體分析

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.