If the program running in JVM is full of its memory heap and persistent storage region, and the program wants to create an object instance, the garbage collector will start, try to release enough memory to create this object. At this time, if the garbage collector is unable to release enough memory, it will throw an OutOfMemoryError memory overflow error.
Sun jvm memory management method:
SUN's JVM is similar to the human family, that is, creating objects in a place, giving it multiple chances of death before it occupies space for a long time. sun jvm is divided:
1. Young generation (Young generation), including EDEN and two survivor spaces (From space and To space)
2. Old generation (Old generation)
3. Permanent generation (Permanent generation)
Generally, the data partitions of Java virtual machines are not necessarily physical partitions ):
1. Heap: Mainly stores object instances and threads share
2. STACK: stores the method call status of a specific thread, exclusively occupied by the thread
3. Local method Stack: stores the call status of local methods and exclusively occupies threads.
4. PC register: Anyone who has learned the operating system course knows that the thread is exclusive.
5. Method Area: Mainly stores type information and thread sharing
Therefore, when a memory overflow error is thrown, a message indicating the type of Memory leakage is displayed, which is generally divided by region:
1. heap) Memory leakage java. lang. OutOfMemoryError: Javaheap space: everyone is familiar with it. You can solve this problem by setting-Xms2048m-Xmx4096m.
2. stack) Memory leakage: there are too many intermediate variables maintained during the running of the current thread. For example, a common endless loop causes stack over flow.
3. method Area permanent heap) Memory leakage, that is, java. lang. outOfMemoryError: PermGen space: the cause of the error is directly related to the type loading and unloading. You can solve this problem by setting-XX: MaxNewSize = 256 m-XX: MaxPermSize = m.
Generally, when the server memory is too small and a large number of access services are provided, too many data objects may be cached, resulting in heap memory overflow. When the web application continues to expand, when the size of the loaded lib Library reaches 4 MB, it is easy to report PermGen OOM, that is, the method zone overflow.
Write the parameters to the environment variables on the Linux Server:
- export CATALINA_OPTS="-Xms2048m -Xmx4096m"
- export JAVA_OPTS="-XX:MaxNewSize=256m -XX:MaxPermSize=256m"
Xmx cannot exceed 80% of the server's physical memory