当前位置:网站首页>What is oom, why it happens and some solutions
What is oom, why it happens and some solutions
2022-07-26 12:03:00 【pan_ junbiao】
1、 What is? OOM
OOM, Full name “Out Of Memory”, Translated into Chinese “ Out of memory ”, originate java.lang.OutOfMemoryError. Take a look at the official statement about : Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector. That is to say , When JVM Because there is not enough memory to allocate space for the object and the garbage collector has no space to recycle , You'll throw this out error( notes : Not exception, Because this problem is too serious to be applied ).
2、 why OOM
Why is there no memory ? There are two reasons :
(1) Less allocated : For example, the memory available to the virtual machine itself ( Usually through the start-up VM Parameter assignment ) too little .
(2) Too many apps , And not released after use , wasted . This will cause memory leakage or memory overflow .
Memory leak : The used memory has not been released , Cause the virtual machine can't use the memory again , At this point, the memory leaks , Because applicants don't have to , And can't be assigned to others by virtual machine .
out of memory : The requested memory exceeds JVM The memory size that can be provided , This is called overflow .
In the days when there was no automatic garbage collection , such as C Language and C++ Language , We must be personally responsible for the application and release of memory , If memory is requested , After use, I forgot to release , such as C++ Medium new Yes, but not delete, Then it may cause memory leakage . Occasional memory leaks may not cause problems , A large number of memory leaks may lead to memory overflow .
And in the Java In language , Due to the existence of automatic garbage collection mechanism , therefore , We generally don't have to actively release the memory occupied by unused objects , That is, in theory , It doesn't exist “ Memory leak ” Of . however , If it's not coded properly , such as , Put the reference of an object into the global Map in , Although the method is over , But because the garbage collector will recycle memory according to the reference of the object , As a result, the object cannot be recycled in time . If this happens more often , It will cause memory overflow , For example, the caching mechanism often used in the system .Java Memory leaks in , differ C++ I forgot delete, It is often a logical reason to leak .
3、OOM The type of
JVM Memory model :
according to JVM standard ,JAVA The virtual machine will manage the following memory areas when running :
- Program counter : The line number indicator of bytecode executed by the current thread , Thread private .
- JAVA Virtual machine stack :Java Memory model for method execution , Every Java The execution of the method corresponds to the operation of a stack frame into and out of the stack .
- Native Method Stack : similar “ JAVA Virtual machine stack ”, But for native Method provides a memory environment .
- JAVA Pile up : Where object memory is allocated , The main area of memory garbage collection , All threads share . It can be divided into Cenozoic , Old generation .
- Method area : Used for storage has been JVM Class information loaded 、 Constant 、 Static variables 、 Real time compiler compiled code and other data .Hotspot Medium “ Forever ”.
- Runtime constant pool : Part of the method area , Store constant information , Such as various literal quantities 、 Symbol references, etc .
- Direct memory : Not at all JVM Part of the runtime data area , Directly accessible memory , such as NIO I'll use this part .
- according to JVM standard , Except that the program counter will not throw OOM Outside , Each other memory area may throw OOM.
The most common OOM There are three situations :
- java.lang.OutOfMemoryError: Java heap space ------>java Heap memory overflow , This is the most common case , It is usually caused by memory leak or improper heap size setting . For memory leaks , Need to find the leak code in the program through the memory monitoring software , The heap size can be determined by virtual machine parameters -Xms,-Xmx And so on .
- java.lang.OutOfMemoryError: PermGen space ------>java Permanent generation overflow , The method area overflowed , It usually occurs in a large number of Class perhaps jsp page , Or use cglib And so on , Because there will be a lot of Class Information is stored in the method area . This can be solved by changing the size of the method area , Use similar -XX:PermSize=64m -XX:MaxPermSize=256m Form modification . in addition , Too many constants, especially strings, can also cause method area overflow .
- java.lang.StackOverflowError ------> I can't throw it OOM error, But it's also quite common Java out of memory .JAVA Virtual machine stack overflow , Generally, it is caused by the existence of dead loop or deep recursive call in the program , If the stack size is set too small, this overflow will occur . You can use virtual machine parameters -Xss To set the stack size .( Comments from netizens :SOF It doesn't count OOM.OOM yes JVM out of memory , and SOF Is only stack memory overflow , Create stack frame overflow through recursive infinite loop , The principle is different .)
4、OOM analysis –heapdump
want dump Memory image of heap , There are two ways to do this :
Set up JVM Parameters -XX:+HeapDumpOnOutOfMemoryError, Set when OOM Automatically dump Pile up information . However, this method needs to be improved JDK5 Above version .
Use JDK Self contained jmap command ."jmap -dump:format=b,file=heap.bin " among pid Can pass jps obtain .
dump After heap memory information , Need to be right dump Analysis of the documents , To find OOM Why . Common tools are :mat: eclipse memory analyzer, be based on eclipse RCP Memory analysis tools . For more information, see http://www.eclipse.org/mat/, Recommended .
jhat:JDK Self contained java heap analyze tool, You can change the objects in the heap to html In the form of , Including the number of objects , Size and so on , And support object query language OQL, After analyzing the related applications , Can pass http://localhost:7000 To access the analysis results . It is not recommended to use , Because in the actual investigation process , Generally speaking, it starts from the production environment dump File out , Then pull it to your own development machine for analysis , therefore , It's better to use advanced analysis tools, such as the previous one mat To be efficient .
This link :IBM Developer Provides a way to adopt mat Examples of analysis .
Be careful : because JVM The specification is not correct dump Define the format of the file , So different virtual machines produce dump The files are not the same . In the analysis , Different analysis tools need to be used for the output of different virtual machines ( Of course , Some tools can be compatible with the formats of multiple virtual machines ).IBM HeapAnalyzer It's also analysis heap A commonly used tool for .
Original author :Qi_Meng6
Original address :https://blog.csdn.net/qq_42447950/article/details/81435080
More detailed learning articles are recommended : What is? OOM, why OOM And some solutions _ Blog full of notes -CSDN Blog _oom The cause of the abnormality and the solution
边栏推荐
- 代码实例详解【可重入锁】和【不可重入锁】区别?
- [communication principle] Chapter 1 -- Introduction
- Ga-rpn: recommended area network for guiding anchors
- 开放原子开源基金会OpenHarmony工作委员会主席侯培新寄语OpenAtom OpenHarmony分论坛
- Several inventory terms often used in communication
- Codepoint 58880 not found in font, aborting. Flutter build APK reports an error
- Talking about web vitals
- Redis database, which can be understood by zero foundation Xiaobai, is easy to learn and use!
- [communication principle] Chapter 2 -- deterministic signal
- 种种迹象表明,Apple将有望支持AV1
猜你喜欢

浅谈Web Vitals

Cohere博客:在生产环境中运行大型语言模型-推理框架概览

Metauniverse gamefi chain game system development NFT Technology

向日葵远程控制为何采用BGP服务器?自动最优路线、跨运营商高速传输

专访即构科技李凯:音视频的有趣、行业前沿一直吸引着我

FPGA入门学习(三)- 38译码器

el-form 每行显示两列,底部按钮居中

Recalling Sister Feng

transformer一统天下?depth-wise conv有话要说

MICCAI2022论文 | 进化多目标架构搜索框架:在COVID-19三维CT分类中的应用
随机推荐
《多线程下ThreadLocal使用场景实例》
Modeling essay series 151 SCLC engineering experiment 4-sclc object
What is per title encoding?
JSJ-3/AC220V时间继电器
面试官:如何处理高并发?
On the construction and management of low code technology in logistics transportation platform
[ten thousand words long text] Based on LSM tree thought Net 6.0 C # realize kV database (case version)
System call capture and analysis - modify kernel methods to add system calls
百问百答第48期:极客有约——可观测体系的建设路径
什么是OOM,为什么会OOM及一些解决方法
Pytest interface automation test framework | rerun failed cases
Modeling essay series 150 SCLC engineering experiment 3-srule
CVPR 2022 new SOTA for monocular depth estimation new CRFs: neural window fullyconnected CRFs
零基础小白也能懂的 Redis 数据库,手把手教你易学易用!
Ubenwa, a start-up under Mila, received an investment of US $2.5 million to study the AI diagnosis of infant health
Who is responsible for the problems of virtual idol endorsement products? And listen to the lawyer's analysis
[countdown 10 days] Tencent cloud audio and video special is about to meet, and the thousand yuan prize is waiting for you!
V00 - 年纪大了,想做啥就做啥吧
Miccai2022 paper | evolutionary multi-objective architecture search framework: application in covid-19 3D CT classification
需不需要上线MES系统,你在纠结什么?