java内存想法一

来源:互联网 发布:淘宝主播收入怎么算 编辑:程序博客网 时间:2024/04/28 08:51

测试代码 :


package com.taobao.consign.topmapping;public class GcTest {private static final int _1mb = 1024 * 1024 ;public static void main(String[] args) { // 测试参数,eclipse直接设置  -Xms20M -Xmx20M -Xmn10M  -XX:PermSize=10M  -XX:MaxPermSize=10M -XX:+PrintGCDetailsbyte[] a , b ,c ,d ,e ,f ,g;a= new byte[2 * _1mb];b= new byte[2 * _1mb];c= new byte[2 * _1mb]; //6d= new byte[4 * _1mb]; //10e= new byte[2 * _1mb]; //14//f= new byte[4 * _1mb]; // 18//g= new byte[2 * _1mb]; //22}}


控制台的输出:

[GC [DefNew: 6820K->363K(9216K), 0.0066686 secs] 6820K->6507K(19456K), 0.0066997 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] Heap def new generation   total 9216K, used 6925K [0x36870000, 0x37270000, 0x37270000)  eden space 8192K,  80% used [0x36870000, 0x36ed86e8, 0x37070000)  from space 1024K,  35% used [0x37170000, 0x371caea8, 0x37270000)  to   space 1024K,   0% used [0x37070000, 0x37070000, 0x37170000) tenured generation   total 10240K, used 6144K [0x37270000, 0x37c70000, 0x37c70000)   the space 10240K,  60% used [0x37270000, 0x37870030, 0x37870200, 0x37c70000) compacting perm gen  total 10240K, used 375K [0x37c70000, 0x38670000, 0x38670000)   the space 10240K,   3% used [0x37c70000, 0x37ccdde0, 0x37ccde00, 0x38670000)    ro space 10240K,  51% used [0x38670000, 0x38b9dc00, 0x38b9dc00, 0x39070000)    rw space 12288K,  55% used [0x39070000, 0x3970c300, 0x3970c400, 0x39c70000)

看到这样的输出,也许你能明白。

java堆是= 年轻代+年老代

而持久代是单独分配的。

java持久代一般都是代码,方法,常量....


以上两个观点,很多网上文章都是错的。



0 0
原创粉丝点击