This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Garbage Collection doubt

 
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes answer will be intermediate
 
Water! People swim in water! Even tiny ads swim in water:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic