MAT (Memory Analyzer Tool)
A heap dump is a snapshot of the complete Java object graph on a Java application at a certain point in time. It is stored in a binary format called HPROF.
It includes all objects, fields, primitive types and object references.
package com.src.javaetutorials;
import java.lang.management.ManagementFactory;
public class TestDump {
public static void main(String[] args) throws InterruptedException {
System.out.println(getProcessId());
Thread.sleep(2000);
while (1 < 2)
System.out.println("Hi");
}
public static String getProcessId() {
String pname = ManagementFactory.getRuntimeMXBean().getName();
System.out.println("process name = " + pname);
String pid = pname;
int i = pname.indexOf("@");
if (i != -1)
pid = pname.substring(0, i);
System.out.println("process id = " + pid);
return pid;
}
}
To configure your application to produce a heap dump whenever an OutOfMemory Error is thrown, add the following vm argument:
-XX:+HeapDumpOnOutOfMemoryError
There are two calculations, Shallow Heap and Retained Heap. Shallow heap is the amount of memory consumed by one object. An Object requires 32 (or 64 bits, depending on the architecture) for each reference. Primitives such as integers and longs require 4 or 8 bytes, etc… While this can be interesting, the more useful metric is the Retained Heap.
User has the choice to divide Histogram on the basis of Class Loader or Classes
References:
http://www.vogella.com/tutorials/EclipseMemoryAnalyzer/article.html
http://eclipsesource.com/blogs/2013/01/21/10-tips-for-using-the-eclipse-memory-analyzer/
No comments:
Post a Comment