Câu hỏi phỏng vấn Java
Câu hỏi

When does an Object becomes eligible for Garbage Collection in Java ?

Câu trả lời

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:

  1. 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[1][3][4][6].

  2. 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[1][4][6].

  3. 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[1][4][7].

  4. Anonymous Objects: Objects without any explicit reference (anonymous objects) are immediately eligible for garbage collection once they are no longer in use, typically after the execution of the line of code in which they were created if no references to them are stored[1][4][6].

  5. Island of Isolation: Objects that reference each other but are c...

junior

junior

Gợi ý câu hỏi phỏng vấn

senior

What is Perm Gen space in Heap ?

middle

What is the volatile keyword useful for?

middle

What is the difference between doGet() and doPost() ?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào