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

必须得加个队列,因为每次被回
边栏推荐
- GIS数据漫谈(六)— 投影坐标系统
- Examples of AC simulation and S-parameter simulation of ADS simulation
- 一文简述:SRv6基本原理
- Ue5 gas learning notes 1.4 attribute set
- ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法
- MySQL index usage and optimization
- 记录自己在厦门两年来的面试经历--完结篇
- 直播|StarRocks 技术内幕 :低基数全局字典优化
- UE5 GAS 学习笔记8.0参考资料
- Is it difficult for novices to change careers through self-study software testing?
猜你喜欢

When golang encounters high concurrency seckill

Detailed explanation of oscilloscope probe

Introduction and advanced level of MySQL (6)

Multithreading and high concurrency -- source code analysis AQS principle

Gateway入门

Tencent Tang Daosheng: open source is a new mode of production and collaboration in the era of industrial Internet

Apple develops a complete creation process of Apple certificate and description file

#夏日挑战赛#【FFH】JS自定义组件:DIY一个随点随用的键盘!(一)

It is said that software testing is the worst in the IT industry. Is that so?

MYSQL入门与进阶(六)
随机推荐
数字化转型中的DevOps——弹性合作
Docker搭建Mysql主从复制
Docker builds MySQL master-slave replication
Iptables configuration
Ue5 gas learning notes 1.3 attribute
Ue5 gas learning notes 1.1 capability system component
MongoDB数据库复制表
Look at Devops construction from SRE
LVS手册
Ue5 gas learning notes 1.5 gameplay effects game effects
What skills do you need to master when learning software testing zero foundation?
haproxy实现代理配置
Ue5 gas learning notes 1.4 attribute set
Ue5 gas learning notes 0.2 configuration plug-in
Introduction to main parameters of antenna
一文简述:SRv6基本原理
Brief introduction to the principle of spectrometer II
GO exe生成图标版本信息
LeetCode_1137_第N个泰波那契数
Go语言系列之日志库zap