最近因為系統問題,所以又對Memory Analysis工具進行複習(for eclipse的)
通過dump出來的檔案,然後在eclipse上用Memory Analysis工具(可以線上安裝很簡單)
記憶體流失尋找思路一:
開啟Leak Suspects->Problem Suspect N下的“Details”
開啟此頁面後,有幾個內容:
1、引用累計關係(shortest paths to the accumulation point)
2、儲存物件(accumulated objects)
3、儲存物件所屬類名(accumulated objects by Class)
這種方式很簡單並且很直觀,知道那些對象了去尋找類和引用點。
記憶體流失尋找思路二:
1、開啟長條圖(Histogram),過濾找到自己的類,然後在此記錄上右鍵“list objects”下選擇“with incoming references”
得到是那些對象引用了此類。
2、再從這些對象記錄選擇一條右鍵“Path to GC Roots”->"exclude weak references",得到層次參考關聯性,就知道了point。
如果對代碼很熟悉,能猜出是那個類會引起泄漏,就可以用這種方式
備忘: Shallow vs. Retained Heap
Shallow heap is the memory consumed by one object. An object needs 32 or 64 bits (depending on the OS architecture) per reference, 4 bytes per Integer, 8 bytes per Long, etc. Depending on the heap dump format the size may be adjusted (e.g. aligned to 8, etc...) to model better the real consumption of the VM.
Retained set of X is the set of objects which would be removed by GC when X is garbage collected.
Retained heap of X is the sum of shallow sizes of all objects in the retained set of X, i.e. memory kept alive by X.
關於相關更詳細的資料可以參考說明和網上資料。