What will the GC do if there is a two-level soft link object

I know that in Java we have the concept of soft link. What to do, if:

1) There is a soft link "sf" refers to object A

2) In object A, it has a strong reference to object B

3) objects A and B are not mentioned anywhere else.

By definition, object A and object B are “mildly reachable,” right?

Then let's say that we are running out of memory, GC starts up. Is it possible that the GC will recycle object B, but not object A?

If in this case, if we want to access object B through "sf", it will be zero. How java avoids such a case?

I do not see any explanation in java doc.

+3
source share
3

, , GC . , GC B, A?

. GC . (, . , ... , .)

javadoc java.lang.ref.

", , , , , .

... " " , , phantom .

, , . , , .

, , . () GC "" , , , . ( , ...)

+6

, , GCs , .

GC (, Java .NET, ) root pointers, ( java, ) . GC , , . , .

: ) ) . , , JVM, .

, :

  • GC A, GCed.
  • GC A ( ). A GCed, B GCed, .
+2

From the docs:

"An object is in an inaccessible state if it is inaccessible, but it can be reached through a soft link."

“An object can be reached if it can be reached by some thread without going through any reference objects”

I think this is pretty clear. B is easily achievable because this is only achieved by moving the soft link.

Specified Documents

+1
source

All Articles