When does an Object becomes eligible for Garbage Collection in Java ?
When does an Object becomes eligible for Garbage Collection in Java ?
An object becomes eligible for garbage collection in Java when it is no longer reachable by any live references from the executing code. This can occur in several scenarios:
Nullifying a Reference: If the reference to an object is explicitly set to null, the object becomes unreachable unless it is referenced from another live path in the application.
Reassigning a Reference: When a reference variable is assigned a new object, the previous object that was referenced by this variable becomes unreachable if no other references to it exist.
Object Created Inside a Method: Objects created inside a method are eligible for garbage collection after the method's execution if they are not returned or stored in references outside of the method.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.