当前位置:网站首页>JVM垃圾回收概述
JVM垃圾回收概述
2022-07-06 09:30:00 【机智的爆爆哥】
带着问题学习更有益于集中我们的注意力,我带着问题来展开这一篇章。
1. 什么是垃圾?
简单的问题,但往往很多人都答不上来,这就是思维上的一种误区,好了不多bb了。
简单来讲,当一个对象没有被任何引用指向,那它就成为了垃圾,如果一个人不被任何人所需要,那他就是垃圾了(例子不好,狗头保命)。
当这样的垃圾多了,而没有被及时的清理,就很容易造成内存溢出了。
2. 为什么需要垃圾回收?
跟生活联系起来,如果垃圾始终放在那里,那么日积月累,房间就变成垃圾堆了,还能住人吗?
对于程序也是这样,最终内存被消耗殆尽,只剩下一堆无用的对象,白白浪费的资源。
而一旦有了垃圾回收,无用对象被清理,多出来的空间又可以存放新的对象了。
3. 早期的内存管理
我们都知道,Java有着自动垃圾回收的机制,这也是C,C++程序员所羡慕的一点,因为他们需要进行手动内存申请,内存释放,而如果忘记释放,就会造成内存泄漏。
什么是内存泄漏?
如果一个对象没有引用指向了,那就是无用对象,但是由于某种原因,并没有被垃圾回收,这就是内存泄漏。
4. Java的自动内存管理
自动的垃圾回收机制使得我们Java程序员无需申请或者释放内存,但是这也弱化了我们在内存溢出时处理问题的能力,所以了解垃圾回收机制对于我们来说还是极为重要的,我们可以借助一些监控或者调优的工具来解决对应的问题。
这里需要强调,GC和OOM只会发生在堆空间和方法区,而方法区的垃圾回收是没有强制规定的,有些JVM其实没有对方法区进行垃圾回收,但是我们默认的HotSpot还是会有的。
垃圾回收重点关注新生代,较少收集于老年代,几乎不动方法区,切记切记!!!
边栏推荐
- 这群程序员中的「广告狂人」,把抖音广告做成了AR游戏
- MySQL日期函数
- redux使用说明
- Conception du système de thermomètre numérique DS18B20
- ~74 JD top navigation bar exercise
- 唯有学C不负众望 TOP5 S1E8|S1E9:字符和字符串&&算术运算符
- Activiti目录(一)重点介绍
- GCC error: terminate called after throwing an instance of 'std:: regex_ error‘ what(): regex
- Ruoyi-Cloud 踩坑的BUG
- Control transfer instruction
猜你喜欢
Assembly language addressing mode
Log4j2 major vulnerabilities and Solutions
ByteDance open source Gan model compression framework, saving up to 97.8% of computing power - iccv 2021
Alibaba cloud server builds SVN version Library
~82 style of table
arithmetic operation
汇编语言寻址方式
100张图训练1小时,照片风格随意变,文末有Demo试玩|SIGGRAPH 2021
~Introduction to form 80
was unable to send heartbeat
随机推荐
数据传送指令
Use of mongodb in node
Many papers on ByteDance have been selected into CVPR 2021, and the selected dry goods are here
Fdog series (VI): use QT to communicate between the client and the client through the server (less information, recommended Collection)
Basic knowledge of assembly language
The 116 students spent three days reproducing the ByteDance internal real technology project
吴军三部曲见识(五) 拒绝伪工作者
Fdog series (III): use Tencent cloud SMS interface to send SMS, write database, deploy to server, web finale.
姚班智班齐上阵,竞赛高手聚一堂,这是什么神仙编程大赛?
字节跳动海外技术团队再夺冠:高清视频编码已获17项第一
Shell_ 00_ First meeting shell
控制转移指令
Shell_ 03_ environment variable
MySQL date function
8086 segmentation technology
Eureka single machine construction
唯有学C不负众望 TOP1环境配置
Full record of ByteDance technology newcomer training: a guide to the new growth of school recruitment
Activit fragmented deadly pit
The most lost road I have ever walked through is the brain circuit of ByteDance programmers