当前位置:网站首页>The difference between JVM memory overflow and memory leak
The difference between JVM memory overflow and memory leak
2022-07-26 12:03:00 【pan_ junbiao】
1、 Distinction of concepts
1.1、 Memory leak (memory leak)
After program running , There is no release Memory space occupied .
A memory leak It doesn't seem to have a big impact , But memory leaks Keep accumulating , Eventually, the available memory will become less and less .

for instance , The total memory size is 100 MB, Yes 40MB Of memory has been unable to recycle , Then only 60MB . this 40MB Memory leak .
Memory leak , After the program runs , No free memory .
1.2、 out of memory (out of memory)
Program runtime , When applying for memory space , There is not enough memory space for its normal use , The program stops , And throw out of memory .
For example, when the program is running, it applies for a 10MB Space , But the current available memory is only 5MB, The program doesn't work properly , This is memory overflow .
out of memory , It can be understood that the memory required for program operation is greater than the currently available memory .
1.3 give an example
(1) In singleton mode , The lifecycle of the singleton is as long as the application , So if a singleton program holds a reference to an external object , Then this external object cannot be recycled , Will lead to Memory leak The birth of .
(2) Some offer close Due to the unclosed resources of Memory leak . Database connection (dataSource.getConnection() ), network connections (socket) and IO The connection of the stream must be in finally in close, Otherwise it can't be recycled .
(3) Read large files , The file read at one time is larger than the available memory , It can lead to out of memory . The available memory is 1G, How to read 2G What about the documents ? To build a 100MB Byte array of , read 10 Time .
2、 The difference and connection between the two
2.1 difference
Memory leak : After program running , The occupied memory is not fully released .
out of memory : Program runtime , The memory required is larger than the currently available memory , Out of memory , Program cannot continue , Throw out “ out of memory ”, The program is interrupted , end .
2.2 contact
once Memory leak It may have no obvious impact on the operation of the program , many times Memory leak Will eventually lead to out of memory .
For example, the total memory size is 100MB, There are , Yes 10MB There is no release , At present Available memory also 90MB, The program can also run . But after many runs , Available memory Ultimately for 0, When there is no memory available or memory is insufficient , The next time the program runs , Because of insufficient memory , And it appears out of memory .
3、 The causes and solutions of memory overflow
3.1 Cause of memory overflow
There are many reasons for memory overflow , Xiaobian lists the following common :
- The amount of data loaded in memory is too large , Such as fetching too much data from the database at one time ;
- There are references to objects in collection classes , Not empty after use , bring JVM Can't recycle ;
- There are dead loops in the code or loops that produce too many duplicate object entities ;
- In the third-party software used BUG;
- The memory value of startup parameter is set too small .
3.2 Memory overflow solution
First step , modify JVM Launch parameters , Add memory directly .(-Xms、-Xmx Parameters must not forget to add )
The second step , Check the error log , see “OutOfMemory” Whether there are other anomalies or errors before the error .
The third step , Walk through and analyze the code , Find out where a memory overflow might occur .
Focus on the following points :
1. Check the database query , Is there a query to get all the data .
Generally speaking , If you take 100000 records to memory at a time , May cause memory overflow .
This problem is more hidden , Before going online , There is less data in the database , It's not easy to have problems , After the launch ,
There's a lot of data in the database , A query may cause memory overflow . Therefore, the database query should be paged as much as possible .
2. Check the code for dead loops or recursive calls .
3. Check if there is a large loop that repeatedly generates new object entities .
4. Check the database query , Is there a query to get all the data .
Generally speaking , If you take 100000 records to memory at a time , May cause memory overflow .
This problem is more hidden , Before going online , There is less data in the database , It's not easy to have problems ,
After the launch , There's a lot of data in the database , A query may cause memory overflow . Therefore, the database query should be paged as much as possible .
5. Check List、MAP Wait until the collection object is used , Problems not cleared .
List、MAP The collection object will always have a reference to the object , So that these objects cannot be GC Recycling .Step four , Use the memory view tool to dynamically view memory usage .
Original author :Sharley
Original address :https://www.cnblogs.com/Sharley/p/5285045.html
边栏推荐
- Network protocol: tcp/ip protocol
- 需不需要上线MES系统,你在纠结什么?
- C language code quantity statistical tool
- System call capture and analysis conclusion making system call log collection system
- 种种迹象表明,Apple将有望支持AV1
- 4.1 configure MySQL and register login module
- pytest接口自动化测试框架 | 使用多个fixture
- System call capture and analysis - modify kernel methods to add system calls
- 大佬们,cdc oracle 怎么设置从指定scn号开始读取,或是怎么设置只读全量的归档,不去读取快
- Miccai2022 paper | evolutionary multi-objective architecture search framework: application in covid-19 3D CT classification
猜你喜欢

Pytoch deep learning quick start tutorial -- mound tutorial notes (II)
![[download attached] a powerful web automated vulnerability scanning tool - Xray](/img/5e/1db72ce9bf758b1e68e8d6d2026302.png)
[download attached] a powerful web automated vulnerability scanning tool - Xray

Real time synchronization and conversion of massive data based on Flink CDC

Acwing727. Diamond pattern

Sword finger offer 25. merge two sorted linked lists

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

Pytest interface automated testing framework | common plug-ins of pytest

Yuancosmos daily | yuancosmos social app "Party Island" product off the shelves; Guangzhou Nansha yuanuniverse industrial agglomeration zone was unveiled; The inter ministerial joint conference system

使用fastJson中的JSONObject对象简化POST请求传参

征婚故事
随机推荐
【通信原理】第三章 -- 随机过程[上]
V00 - 年纪大了,想做啥就做啥吧
Audio and video+
Sunflower senior product director technology sharing: how to apply in AD domain environment
大佬们,cdc oracle 怎么设置从指定scn号开始读取,或是怎么设置只读全量的归档,不去读取快
CVPR 2022 new SOTA for monocular depth estimation new CRFs: neural window fullyconnected CRFs
Why BGP server is used in sunflower remote control? Automatic optimal route and high-speed transmission across operators
Li Kai: the interesting and cutting-edge audio and video industry has always attracted me
Several inventory terms often used in communication
Flutter 学习之路
Recalling Sister Feng
transformer一统天下?depth-wise conv有话要说
Pytoch deep learning quick start tutorial -- mound tutorial notes (II)
Harbor2.2 quick check of user role permissions
网络协议:TCP/IP协议
Transactional事务传播行为?
3.2 create menu and game pages (Part 2)
CVPR 2022 单目深度估计新SOTA—NeW CRFs:Neural Window Fullyconnected CRFs
Introduction to FPGA (I) - the first FPGA project
Fineos announced the open registration of grouptech connect activities in 2022