Java – do immortal objects really exist?

In this article: xamarin – use weak references to prevent immortal objects. It says that if two objects strongly reference each other, they will become imortal, which means that GC cannot collect them, even if the application no longer uses these objects

However, in these two so discussions:

Garbage collector and circular reference

Circular References Cause Memory Leak?

It seems that circular references can be handled by GC as long as the application no longer uses these objects

Did I misunderstand anything? Does Java GC behave differently on Android? I'm really confused. Any comment is applicable. Thank you!

resolvent:

I'm not sure what language or environment your problem is, but in Java, there is no "immortal object" you describe. Java garbage collection is not based on reference counting: it is based on accessibility from the root. Since your two objects are not referenced by any other object in the application, they are eligible for garbage collection

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>