In Swift, great emphasis has been placed on strong reference cycle, and different ways to avoid it. If there are strong reference cycle between two variables, they will keep each other in memory forever, and cause the program to crash if large images or videos are been kept in memory by strong reference cycle.
I was just wondering if such concept exist in Java? Is it possible to unintentionally create something similar to strong reference cycle in Java? I have several months of Java experience, but I have never heard of anyone mentioning such concept in Java, even though Java do use reference variables to point to objects.
It seems that swift uses "reference counting" to detect object liveness: each object has a counter associated with it that gets incremented if a new reference to that object is created and gets decremented if a reference to that object disappears. An object is dead if the reference count is zero, meaning that there are no more references to it.
Java on the the other hand uses "reachability" as a measure of liveness: an object is alive as long as there exists a reference chain from some "running code" to the object.
There are pros and cons to both approaches:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With