aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection doubt" Watch "Garbage Collection doubt" New topic
Author

Garbage Collection doubt

Gitesh Ramchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 274
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

Joined: Aug 24, 2007
Posts: 10
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

Joined: Mar 20, 2006
Posts: 106
yes answer will be intermediate


Thanks, Prafulla Patil
SCJP, SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection doubt