当前位置:网站首页>为什么会没有内存了呢
为什么会没有内存了呢
2022-08-11 07:25:00 【学习微站】
为什么会没有内存了呢?原因不外乎有两点:
1)分配的少了:比如虚拟机本身可使用的内存(一般通过启动时的VM参数指定)太少。
2)应用用的太多,并且用完没释放,浪费了。此时就会造成内存泄露或者内存溢出。
内存泄露:申请使用完的内存没有释放,导致虚拟机不能再次使用该内存,此时这段内存就泄露了,因为申请者不用了,而又不能被虚拟机分配给别人用。
内存溢出:申请的内存超出了JVM能提供的内存大小,此时称之为溢出。
1、当发生OOM时,服务已基本不可用,并且会出现以下明显报错信息。
2.JVM启动参数设置 -XX:+HeapDumpOnOutOfMemoryError 当发生OOM时自动输出堆的内存快照
-XX:HeapDumpPath=/tmp 输出目录将dump文件java_pid1.hprof拷到本地如果忘记设置启动参数,也可以通过命令行获取dump文件使用JDK自带的jmap命令:jmap -dump:format=b,file=heap.bin
3、本地先安装eclipse, 再安装MAT(Memory Analyzer Tool)工具,使用mat工具打开java_pid1.hprof文件,根据mat可以快速定位问题
预防
1、根据业务合理设置java内存大小,以及不定时查看业务运行时内存使用情况, 及时调整内存大小。
2、在写代码时,应该有意识避免写查询大对象sql。
3、针对循环业务要有意识避免内存不能释放进而导致OOM。
边栏推荐
- Activity的四种状态
- Pico neo3 Unity Packaging Settings
- Service的两种状态形式
- 1.2-误差来源
- 1002 Write the number (20 points)
- 1081 Check Password (15 points)
- Evolution and New Choice of Streaming Structured Data Computing Language
- matplotlib
- There may be fields that cannot be serialized in the abnormal object of cdc and sqlserver. Is there anyone who can understand it? Help me to answer
- 1071 Small Gamble (15 points)
猜你喜欢
Write a resume like this, easy to get the interviewer
囍楽云任务源码
Active users of mobile banking grew rapidly in June, hitting a half-year high
测试用例很难?有手就行
零基础SQL教程: 基础查询 05
JUC并发编程
Do you know the basic process and use case design method of interface testing?
TF通过feature与label生成(特征,标签)集合,tf.data.Dataset.from_tensor_slices
The easiest trick to support quick renaming of various files
2.1 - Gradient Descent
随机推荐
matplotlib
Active users of mobile banking grew rapidly in June, hitting a half-year high
leetcode: 69. Square root of x
Two state forms of Service
1061 True or False (15 points)
4.1 - Support Vector Machines
oracle数据库中列转行,列会有变化
tf.reduce_mean()与tf.reduce_sum()
从何跟踪伦敦金最新行情走势?
Conditional statements in TF; where()
About # SQL problem: how to set the following data by commas into multiple lines, in the form of column display
机器学习总结(二)
Do you know the basic process and use case design method of interface testing?
1056 Sum of Combinations (15 points)
1051 Multiplication of Complex Numbers (15 points)
js根据当天获取前几天的日期
Service的两种状态形式
redis operation
数仓开发知识总结
求职简历这样写,轻松搞定面试官