当前位置:网站首页>jvm四种引用类型
jvm四种引用类型
2022-07-28 17:06:00 【一梦无痕bzy】
一、强引用:
正常的new出对象被引用指向就是强引用。可直接通过引用操纵对象。gc不会回收被强引用指向的对象,除非引用等于null
二、软引用
new出SoftReference在它的构造方法里嵌套别的对象

1、m指向sr强引用,sr对象指向字节数组软引用。每次gc并不会主动清理软引用,只有当有其他强引用进来,并且堆区空间不够了则才会被清理。可以通过引用.get方法获取嵌套的对象
2、作用:用于缓存,把一些经常用的设为软引用(让SoftReference里嵌套要用到的东西),这样它就不会被gc回收掉,可以被经常使用。而且当内存不够时,它可以随时被其他强引用干掉
三、弱引用
new出WeakReference在它的构造方法里嵌套别的对象
1、内存图如上。只要垃圾回收启动一定会被回收。可以通过引用.get方法获取嵌套的对象
2、作用:在ThreadLocal中防止内存泄露(详见多线程专栏的ThreadLocal)
四、虚引用
new出PhantomReference在它的构造方法里嵌套别的对象

必须得加个队列,因为每次被回
边栏推荐
- UE5 GAS 学习笔记0.1 案例预览
- UE5 GAS 学习笔记 1.1能力系统组件Ability System Component
- UE5 GAS 学习笔记 1.10 预测(Prediction)
- 不理解模块化、组件化、插件化的区别怎么行?
- Ue5 gas learning notes 1.10 prediction
- First understanding of structure
- Docker builds MySQL master-slave replication
- Ue5 gas learning notes 1.2 game Tags
- Introduction to CC cable of USB type-C
- The required error of solidity is reported
猜你喜欢

MYSQL入门与进阶(十)

MYSQL入门与进阶(六)

Error 2003 (HY000) can't connect to MySQL server on 'localhost3306' (10061) solution

Random talk on GIS data (VI) - projection coordinate system

Experimental building - PHP Dafa

Tcp/ip detailed diagram

Wired: who owns the art of the future? Openai allows dall-e users to commercialize their works. At present

DC-DC switching power supply

1.3、链表

Docker搭建Mysql主从复制
随机推荐
What skills do you need to master when learning software testing zero foundation?
Meta Q2财报:营收首次下滑,Metaverse将与苹果竞争
Ue5 gas learning notes 8.0 references
MySQL advanced mvcc (ultra detailed collation)
Golang 打包发布到各个平台
Tencent Tang Daosheng: open source is a new mode of production and collaboration in the era of industrial Internet
数字化洪流 :企业转型中的资源重组与战略冲突
UE5 GAS 学习笔记 1.10 预测(Prediction)
SQL Server stuff and for XML path
专题讲座6 树形dp 学习心得(长期更新)
Tcp/ip detailed diagram
Introduction to the principle of signal source
UE5 GAS 学习笔记 1.2游戏标签
MYSQL入门与进阶(七)
How does Xiaobai learn software testing with zero foundation?
Go's sleep
Apple develops a complete creation process of Apple certificate and description file
Gaode map realizes customized small blue dots, customized point markers, drawing polygon / circular areas, and displaying or hiding customized point markers according to the movement of the map
冒泡排序和相关视频
LeetCode_96_不同的二叉搜索树