• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

garbage collection!!

Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q.58.At what point is the object obj eligible for garbage collection?(sun's mock2)
(Select one correct answer)
public class Test058 {
public String m() {
Object obj = new String("");
String str = null; //1
str = (String)obj; //2
obj = null; //3
return str;
A: After line //1.
B: After line //2.
C: After line //3.
D: Never
Ans -The object is returned by the method and not eligible for garbage collection during
the lifetime of the method.

--> i think even after returning from the method, the object earlier referenced by obj may or not may not(if it is assigned to some ref. variable in the caller method) eligible for garbage collection. Am i right here??
Author & Gold Digger
Posts: 7617
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you're right, the answer should be "Can't say" since we don't know the code of the caller method so we can't state anything about when the object will be gced...
But if the answer was to stay "Never" I would modify the question like this : "When will the object obj be garbage-collected in the lifetime (i.e. during the execution) of this method ?" Answer "Never" (in this method, but maybe in the caller method)
Sun what do you think ??
[This message has been edited by Valentin Crettaz (edited September 24, 2001).]
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic