java OutOfMemoryError investigation

First, what is OOM, what are the reasons

   OOM, also known as memory overflow, leading to several common reasons why an OutOfMemoryError of:

  1. The amount of data loaded in memory is too large, too much data as extracted from a database;
  2. Class has a collection of references to objects, not emptied after use, can not be recycled so that the JVM;
  3. Infinite loop or cycle is repeated excessive physical presence of the object code;
  4. Third-party software used in the BUG;
  5. Memory startup parameter value setting is too small;

Second, by positioning a case investigation

        First, look at the code generated OOM, its semantics is unlimited add elements to the collection

import java.util.*;

public class OomTest{
	
	public static void main(String [] args){
		List<String> list = new ArrayList<String>();
		while(true){
		list.add(new String("test"));
		}
		}
}

 

First introduced the concept used under logs and tools:

What Heap Dump that?
Heap Dump also called the heap dump file, is a Java process memory snapshots at some point in time. Heap Dump is with many types. But on the whole heap dump when the trigger snapshots are stored information java objects and classes. FullGC usually trigger a heap dump file before writing, so save the heap dump file is left after FullGC object information.

IBM heapAnalyzer:

This is the Heap Dump analysis tools, can be downloaded through this connection https://download.csdn.net/download/cts314/8226597

 

To reproduce this problem, we need the command: -Xmx10m go down memory size is 10M. To troubleshoot the problem, we need to generate a heap dump files via the command (-XX: + HeapDumpOnOutOfMemoryError)

 

 As we expected, and she appeared OOM. Red mark at the end of .hprof file, that is, heap dump, he will be generated in the classpath directory.

 

 We find this file, then downloaded before use IBM heapAnalyzer open,

 

 

Then we click on the upper left corner of Analysis select Objects List, you can see the following interface:

 

 

 

We can see totalSize the first two rows of very large, through analysis, we can draw a lot of objects are stored in a list of them.

 

Or we can click on the upper left corner of Analysis choose Tree View, you can see the following interface:

 

 Here we must see it at a glance.

 

Guess you like

Origin www.cnblogs.com/enchaolee/p/11444383.html