Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the four situations of java memory overflow

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of what the four cases of java memory overflow are, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this four cases of java memory overflow. Let's take a look at it.

1. Heap overflow. The heap stores instance objects, but the heap area will be full sooner or later. If the heap memory is set, an exception will be thrown when created.

Public class HeapOOM {static class User {} public static void main (String [] args) {List list = new ArrayList (); while (true) {list.add (new User ());} / * Exception in thread "main" java.lang.OutOfMemoryError:GC overhead limit exceededat com.fdd.test.HeapOOM.main (HeapOOM.java:11) * /

2. Virtual machine stack and local method stack overflow

If the stack depth required by the thread is greater than that allowed by the virtual machine lock, a StackOverflowEror exception is thrown.

An exception occurs if the virtual machine cannot request sufficient storage space when expanding the stack.

Public class StackOutOfMemoryError {public static void main (String [] args) {test ();} private static void go () {System.out.println ("StackOverflowError exception"); test () Exception in thread "main" java.lang.StackOverflowError at sun.nio.cs.ext.DoubleByte$Encoder.encodeLoop (DoubleByte.java:617) at java.nio.charset.CharsetEncoder.encode (CharsetEncoder.java:579) at sun.nio.cs.StreamEncoder.implWrite (StreamEncoder.java:271) at sun.nio.cs.StreamEncoder.write (StreamEncoder.java:125) at java.io.OutputStreamWriter.write (OutputStreamWriter.java:207) at java.io.BufferedWriter. FlushBuffer (BufferedWriter.java:129) at java.io.PrintStream.write (PrintStream.java:526) at java.io.PrintStream.print (PrintStream.java:597) at java.io.PrintStream.println (PrintStream.java:736) at com.fdd.test.StackOutOfMemoryError.go (StackOutOfMemoryError.java:11) at com.fdd.test.StackOutOfMemoryError.go (StackOutOfMemoryError.java:13) * /

3. Method zone and runtime constant pool overflow

4. Native direct memory overflow

DirectMemory capacity can be specified through-XX:MaxDirectMemorySize, if not specified, the default is the same as the value of the Java heap (specified by-Xmx).

This is the end of the article on "what are the four situations of java memory overflow?" Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "what are the four situations of java memory overflow". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report