Java heap Oom (out-of-memory) exception
Run the following procedure to burst the exception Java.lang.OutOfMemoryError:Java heap space
/** * VM args:-xms20m-xmx20m-xx:+heapdumponoutofmemoryerror * @author Zzm */public class Heapoom {static Class Oomobject {}public static void main (string[] args) {list<oomobject> List = new arraylist<oomobject> (); while (true) {lis T.add (New Oomobject ());}}}
Analysis:
1. Memory configuration
The size of the-xms20m heap is 20M
The-xmx20m heap can scale up to 20M, because the heap size is 20M so the heap cannot be extended
-xx:+heapdumponoutofmemoryerror Exporting a heap file when an OutOfMemory exception occurs
Oomobject is used to occupy space, with a list to store oomobject to ensure that each of our generated Oomobject objects can be connected to the gcroot reference chain.
This can result in an Oom exception. Because each object is useful (it can be connected to the gcroot)
The general steps to analyze the Oom problem are as follows
1. There was an oom.
2. Determine if the object where the oom occurred should be the surviving
3. If the object of the oom position should not survive and an oom exception occurs, then our program has a problem writing it.
4. If the location of the Oom object is supposed to survive but an oom exception occurs, then we should adjust the JVM parameters appropriately.
For the current example:
Obviously, we're using a dead loop. Creates an object, and saves an instance of the owning object with a list, causing the JVM to fail to reclaim the created object, resulting in an oom problem
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Reading notes-in-depth understanding of JVM virtual Machine -1.oom