Madhana Gopal Thirunavukkarasu’s Post

GC does not remove objects because they are “old.” It removes objects that are unreachable. That is the key idea. The JVM starts from GC Roots like: stack variables, static fields, active threads, and JNI references. Then it checks: Is there still a live path from any GC Root to this object? If yes, the object stays alive. If no, it becomes eligible for garbage collection. So “orphan” or “zombie” object usually means: an object that no longer has any reachable reference path from GC Roots. How do you keep an object from removal? Keep it reachable. Common ways: hold a live reference store it in a collection keep it in a static field reference it from another live object But there is an important warning: If you keep references longer than needed, GC cannot free them. That is how memory leaks often happen in Java too. The easiest rule to remember is: Reachable = alive Unreachable = collectible Which JVM topic should I explain next: GC roots, heap vs stack, or weak references? #Java #JVM #GarbageCollection #JavaDeveloper #BackendDevelopment #SoftwareEngineering #MemoryManagement #Programming #TechLearning #ComputerScience

  • graphical user interface, website

To view or add a comment, sign in

Explore content categories