JVM - Are WeakReferences collected in minor GC?

前端 未结 6 1039
情歌与酒
情歌与酒 2021-01-05 11:06

I was wondering about that since that would make them less useful. If so, is there a way to make memory weakly referenced only \"garbage\" on major GC?

6条回答
  •  -上瘾入骨i
    2021-01-05 11:25

    You may be thinking of SoftReferences which may be closer to what you want.

    Minor collections will collect any object in the young space. A WeakReference to an object in the young space will be collected on a minor GC. A WeakReference to an object in the tenured space will be collected on tenured collection e.g. Full GC. BTW You can have concurrent collections of only the tenured space.

提交回复
热议问题