hprof內存文件分析,內存分區,類加載


 

 

獲取hprof命令
jmap -dump:format=b,file=/path/file.hprof pid
idea插件篇之java內存分析工具(JProfiler)
Eclipse下的mat差距進行分析 http://www.eclipse.org/mat
jhat C:\Users\xingminghui\file.hprof -J -Xmx512m http://localhost:7000/ http://localhost:7000/showInstanceCounts/includePlatform/

jmap -dump:format=b,file=mem.dat 7528 #將內存使用的詳細情況輸出到mem.dat 文件
通過 jhat -port 7000 C:\Users\xingminghui\mem.dat 可以將mem.dat的內容以web的方式暴露到網絡,訪問http://ip-server:7000查看。

 

 


window獲取進程命令
netstat -ano | findstr 8081

Eclipse Memory Analyzer,查看對象樹和對象空間占用非常的方便
tomcat 查看內存占用量 https://blog.csdn.net/jkler_doyourself/article/details/6033500

https://www.cnblogs.com/KingIceMou/p/6967754.html 內存監控
使用sudo -u admin -H jmap -dump:format=b,file=文件名.hprof pid 來dump內存,生成dump文件
jvisualvm 工具里面有 Heap Dump的功能
jmap -dump:format=b,file=file.hprof 7528
C:\Users\xingminghui\file.hprof

 

 

 

http://localhost:7000/showInstanceCounts/includePlatform/

 

 

 

java內存分區
****方法區
主要用來存儲已被虛擬機加載的類的信息、常量、靜態變量和即時編譯器編譯后的代碼等數據。
****堆
java堆是所有線程所共享的一塊內存,在虛擬機啟動時創建,幾乎所有的對象實例都在這里創建,因此該區域經常發生垃圾回收操作。
****虛擬機棧
1. 虛擬機棧也就是我們平常所稱的棧內存,它為java方法服務,每個方法在執行的時候都會創建一個棧幀,用於存儲局部變量表、操作數棧、動態鏈接和方法出口等信息。
2. 虛擬機棧是線程私有的,它的生命周期與線程相同。



finalize() 對象釋放會調用該方法
HashMap存進去的是t1跟t2指向的地址,t1=null,t2=null的時候,本來按照常理來說,Java回收機制會對那些沒有引用的堆內存對象進行回收,但不幸的是,HashMap依舊會強引用着t1跟t2的堆內存對象,導致GC無法對其進行回收

public class TestMy {
    public static void main(String[] args) {
        TestE t2 = new TestE();
        TestE t3 = null;
        System.out.println(t2+","+t3);
        System.gc();
        System.out.println(t2+","+t3);
        t2=null;
        System.gc();
        //System.out.println(t2+","+t3);
    }
    @org.junit.Test
    private void test1(){
       HashMap map = new HashMap();
       TestE t1 = new TestE();
       TestE t2 = new TestE();
       map.put("1", t1);
       map.put("2", t2);
       t1 = null;
       System.gc();
       System.out.println("第1步" + map);
       t2 = null;
       System.gc();
       System.out.println("第2步" + map);
       map.clear();
       System.gc();
       System.out.println("第3步" + map);
   }
}

public class TestE {
    private String strTest = "該Test對象還存在";
    @Override
    public String toString() {
        return strTest;
    }
    @Override
    protected void finalize() throws Throwable {
        // TODO Auto-generated method stub
        System.out.println("該Test對象被釋放了");
    }
}

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM