Which of the following statements are true? Select all valid answers (a) Objects can explicitly be destroyed using the keyword delete (b) An object will be garbage collected immediately after the last reference to the object is removed. (c) If object obj1 is accessible from object obj2 and obj2 is accessible from obj1, then obj1 and obj2 are not eligible for garbage collection (d) Once an object has become eligible for garbage collection, it will remain eligible until it is destroyed (e) If an object obj1 can access an object obj2 that is eligible for garbage collection, then obj1 is also eligible for garbage collection Ans: e I feel that the option 'c' is also correct. Can anybody explain to me as to why 'c' is a wrong answer? Any comments are also welcome. Thanks, Kezia.
If object obj1 is accessible from object obj2 and obj2 is accessible from obj1, then obj1 and obj2 are not eligible for garbage collection
Imagine the only reference to obj1 is hold by obj2. And that the only reference to ob2 is hold by obj1. That means that they are not reachable from any reachable variable in the program. The g.c. should be able to collect these circularly-referenced objects. This scenario complies with