垃圾回收中对象的五种可达性——强、软、弱、虚、不可达

本文详细介绍了Java中对象的五种可达性状态:强可达、软可达、弱可达、虚可达和不可达,阐述了它们的生命周期和垃圾回收规则。强可达对象不会被GC回收;软可达对象在内存不足时会被回收;弱可达对象在下次GC时会被回收;虚可达对象在被finalize后且有虚引用时的状态;不可达对象则适合被回收。
摘要由CSDN通过智能技术生成

在javaAPI文档
https://docs.oracle.com/javase/8/docs/api/java/lang/ref/package-summary.html
中介绍了Java.lang.ref,它提供了与 Java 垃圾回收器密切相关的引用类。
并且介绍了对象的可达性。


Reachability

Going from strongest to weakest, the different levels of reachability reflect the life cycle of an object. They are operationally defined as follows:

  • An object is strongly reachable if it can be reached by some thread without traversing any reference objects. A newly-created object is strongly reachable by the thread that created it.
  • An object is softly reachable if it is not strongly reachable but can be reached by traversing a soft reference.
  • An object is weakly reachable if it is neither strongly nor softly reachable but can be reached by traversing a weak reference. When the weak references to a weakly-reachable object are
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值