当前位置:网站首页>Causes and solutions of oom (memory overflow)
Causes and solutions of oom (memory overflow)
2022-07-07 07:16:00 【How to solve the problem, only】
One 、 Concept
out of memory (Out Of Memory, abbreviation OOM) It means that there is too much memory in the application system that cannot be recycled or used , Finally, the memory used for program running is larger than the maximum memory provided .
Two 、 Cause
2.1、 Memory leak
Due to the long-term reference of some resources , The garbage collector cannot recycle it , Thus, this resource cannot be released in time , Also known as memory leak . So try not to use all references as strong references , Weak references and soft references can be used where appropriate .
2.2、 Super large objects
Saving multiple consumed memory is too large or when loading a single oversized object , The size of this object exceeds the currently available memory space . For example, query the data in the database , Too many queries at one time , Directly lead to memory overflow . Therefore, if there is too much data in the query database, try to use paging query .
2.3、 All sorts of other reasons
For example, whether there is an dead cycle , Large loops repeat to produce objects , Whether there is a collection object after it is used , Still quoted , Cause unable to clear , Whether improper data structures are used , It leads to too much space and so on .
3、 ... and 、 Solution
3.1、 modify JVM Launch parameters , Add memory directly
JVM By default, the available memory is 64M,Tomcat By default, the available memory is 128MB, For a slightly more complex system, it will not be enough . In a project , Just because the default value used by the startup parameter , Regular report “Out Of Memory” error . therefore ,-Xms,-Xmx( Minimum and maximum size of heap memory ) Parameters must not forget to add .
3.2、 Find out where a memory overflow might occur , And solve
Check the code for dead loops or recursive calls .
Check if there is a large loop that repeatedly generates new object entities .
Check the database query , Is there a query to get all the data .
Check List、Map Wait until the collection object is used , Problems not cleared .
Use the memory view tool to dynamically view memory usage .
Four 、Xmn、Xms、Xmx、Xss Parameter difference - Meaning and understanding
First ,-Xmn、-Xms、-Xmx、-Xss All are JVM Configuration parameters for memory , We can modify these parameters according to different needs , To achieve the best effect of running the program .
4.1、-Xms、-Xmx
-Xms、-Xmx Allocation is used to set the minimum and maximum size of the process heap memory .
4.2、-Xmn
-Xmn Used to set the size of the Cenozoic in the heap . Through this value, we can also get the size of the old generation :-Xmx subtract -Xmn
4.3、-Xss
-Xss Set the amount of memory each thread can use .
In the same physical memory , Reducing this value can generate more threads . Of course, the operating system has a limit on the number of threads in a process , Can't generate... Indefinitely , Experience is in 3000~5000 about .
In addition to these configurations ,JVM There are a lot of configurations , Common ones are as follows :
-XX:PermSize、-XX:MaxPermSize
Allocation is used to set the minimum and maximum size of the permanent generation .Java 8 Later, the method area was removed , Instead, the local meta space Metaspace, Size by -XX:MetaspaceSize and -XX:MaxMetaspaceSize Adjust the .
-XX:MaxTenuringThreshold
Set the survival times of the old generation . If it is 0, Then directly skip the new generation and enter the old generation .
-XX:NewRatio
Set the ratio of the old generation to the new generation , For example, the value is 3, It means that the ratio of Cenozoic generation to old generation is 1:3.
边栏推荐
- linux系统rpm方式安装的mysql启动失败
- Multithreading and high concurrency (9) -- other synchronization components of AQS (semaphore, reentrantreadwritelock, exchanger)
- After the promotion, sales volume and flow are both. Is it really easy to relax?
- Databinding exception of kotlin
- Chinese and English instructions prosci LAG-3 recombinant protein
- Stack Title: nesting depth of valid parentheses
- Bus消息总线
- Config distributed configuration center
- 大咖云集|NextArch基金会云开发Meetup来啦
- Esxi attaching mobile (Mechanical) hard disk detailed tutorial
猜你喜欢
Abnova membrane protein lipoprotein technology and category display
父组件传递给子组件:Props
mips uclibc 交叉编译ffmpeg,支持 G711A 编解码
Bindingexception exception (error reporting) processing
Prime partner of Huawei machine test questions
Tujia, muniao, meituan... Home stay summer war will start
main函数在import语句中的特殊行为
$parent (get parent component) and $root (get root component)
Role of virtual machine
freeswitch拨打分机号源代码跟踪
随机推荐
.net 5 FluentFTP连接FTP失败问题:This operation is only allowed using a successfully authenticated context
MySQL view bin log and recover data
LC 面试题 02.07. 链表相交 & LC142. 环形链表II
MySQL user permissions
Prime partner of Huawei machine test questions
Tujia, muniao, meituan... Home stay summer war will start
Exception of DB2 getting table information: caused by: com ibm. db2.jcc. am. SqlException: [jcc][t4][1065][12306][4.25.13]
Unity C function notes
How does an enterprise manage data? Share the experience summary of four aspects of data governance
软件验收测试
SQLMAP使用教程(四)实战技巧三之绕过防火墙
Anr principle and Practice
Tool class: object to map hump to underline underline hump
请教一下,监听pgsql ,怎样可以监听多个schema和table
Config distributed configuration center
Bindingexception exception (error reporting) processing
ViewModelProvider. Of obsolete solution
Take you to brush (niuke.com) C language hundred questions (the first day)
Leetcode t1165: log analysis
关于数据库数据转移的问题,求各位解答下