Reading notes-in-depth understanding of JVM virtual Machine -1.oom

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.