Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection doubt

 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
void m1() {
Q q1 = null;
for (int i = 0; i < 10; i++) {
q1 = new Q(); // 1
m2(q1); // 2
}
System.out.print("All done"); // 3
}
When the processing of line 3 begins, how many objects of type Q that were created at line 1 have become eligible for garbage collection?
a. 0
b. 1
c. 9
d. 10
e. Indeterminate.
f. Compile-time error
g. Run-time error
h. None of the above
Ans:E

Doubt: Is it always true that in case if the object´┐Żs are passed to a method whose implementation is not shown, we cannot be sure of object's being Garbage Collected, so the answer Intermediate

please help,
gitesh
 
alok Jain
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
Yeah we cannot say for sure because in the called method the references to the Q object can still be maintained and the method returns ..for example a new thread might be created and it has the references to the Q objects ...so unless we know the implementation we cannot say what will be the state of the objects..
 
Prafulla N. Patil
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes answer will be intermediate
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic