The Verbose GC log is defined when the JVM process is started. There are a couple of switches that can be used:
- -verbose:gc — prints basic information about GC to the standard output
- -XX:+PrintGCTimeStamps — prints the times that GC executes
- -XX:+PrintGCDetails — prints statistics about different regions of memory in the JVM
- -Xloggc:<file> — logs the results of GC in the given file
Heap dumps are saved on disk, and the files might be fairly large. A good rule is to make sure that you have at least twice the size of the physical memory free on the disk before you initiate a memory dump.
With those final words of caution out of the way, you should now be ready to run the following command:
jmap -heap:live,format=b,file=FILENAME PID
Determing the cause of the memory leakage:
Using any Heap analysis software, such as jhat in jdk in order to open the heap.
To determine which objects are leaked, sort the classes by total memory usage of all instances of each class. The objects near the top of the list are usually the leaked objects. Then, you can follow the reference chain to them until you find the cause of the memory leak.
A useful heuristic here is that if you sort all the objects by retained heap, you can find the objects that are likely the root cause of the memory leak.
Abstract from http://java.dzone.com/news/how-fix-memory-leaks-java
沒有留言:
張貼留言