Java Programming - Garbage Collections - Discussion

Discussion Forum : Garbage Collections - General Questions (Q.No. 1)
1.
void start() {  
    A a = new A(); 
    B b = new B(); 
    a.s(b);  
    b = null; /* Line 5 */
    a = null;  /* Line 6 */
    System.out.println("start completed"); /* Line 7 */
} 
When is the B object, created in line 3, eligible for garbage collection?
after line 5
after line 6
after line 7
There is no way to be absolutely certain.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
59 comments Page 6 of 6.

Prabavathi.V said:   1 decade ago
Actually, garbage collection object values are always unused and it will never be absolutely certain.

Ashish Mishra said:   1 decade ago
option A

Just bcz of when object reference bcome null then it will eligible to call runtime.gc();

Amit said:   1 decade ago
It will throw an error while creating the reference of the object(a.s(b)).

Arnold villasanta said:   1 decade ago
Yup, D is correct.

No one knows how instance 'a' used 'b' in its method.

Ranjani said:   1 decade ago
It's A. Java is never pass by reference..that's a C language concept..

Konapuram malli said:   1 decade ago
Option A is correct because of that object reference is null.

Mostapha said:   9 years ago
Option D.

It's depends of what a.s (b) will do if it exists.

Yuvaraju said:   9 years ago
We can assign a null to the object, so option D is correct.

Anuja said:   10 years ago
Please explain about option D.


Post your comments here:

Your comments will be displayed after verification.