当前位置:网站首页>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在它的构造方法里嵌套别的对象

必须得加个队列,因为每次被回
边栏推荐
- It is said that software testing is the worst in the IT industry. Is that so?
- UE5 GAS 学习笔记 1.6 技能Gameplay Ability
- 欧美六国最快5日达 菜鸟推出快线产品 优化“端到端”履约服务
- Detailed explanation of network RJ45 interface
- Go并发详解之一
- LVS manual
- Composition and principle of vector network analyzer (vector network)
- 冒泡排序和相关视频
- UE5 GAS 学习笔记0.2配置插件
- 直播|StarRocks 技术内幕 :低基数全局字典优化
猜你喜欢

记录自己在厦门两年来的面试经历--完结篇

Docker builds MySQL master-slave replication

Introduction to oscilloscope

Shenzhen offline registration starrocks on AWS: how to conduct rapid unified analysis of real-time data warehouses

不理解模块化、组件化、插件化的区别怎么行?

MYSQL入门与进阶(五)

MYSQL入门与进阶(一)

MYSQL入门与进阶(八)

直播|StarRocks 技术内幕 :低基数全局字典优化

MQTT over QUIC:下一代物联网标准协议为消息传输场景注入新动力
随机推荐
.net swagger
Meta Q2财报:营收首次下滑,Metaverse将与苹果竞争
Detailed explanation of oscilloscope parameters
MYSQL入门与进阶(十)
UE5 GAS 学习笔记 1.8 游戏特效(GameplayCue)
UE5 GAS 学习笔记 1.4属性集
Introduction to CC cable of USB type-C
Digital torrent: resource reorganization and strategic conflict in enterprise transformation
Ue5 gas learning notes 0.2 configuration plug-in
Msg.value of solidity
Golang concurrency model
Tencent Tang Daosheng: open source is a new mode of production and collaboration in the era of industrial Internet
Record your interview experience in Xiamen for two years -- Conclusion
What is the employment prospect of software testing?
Wired: who owns the art of the future? Openai allows dall-e users to commercialize their works. At present
MySQL日期函数
UE5 GAS 学习笔记 1.1能力系统组件Ability System Component
Zen project management software is an indispensable tool for agile development teams
UE5 GAS 学习笔记 1.9 技能系统全局类(AbilitySystemGlobals)
Mongodb initialization operation