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

Garbage Collection

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q29 from javaprepare.com
29.At what stage in the following method does the string "abc" becomes available for garbage collection. Select the one correct answer.

A.Before statement labelled 1
B.Before statement labelled 2
C.Before statement labelled 3
D.Before statement labelled 4
E.Never.
The answer is D. Should it not be C ? i.e. Before stmt 3.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ankur,
The same question has been discussed here

Ajith
 
Ankur Gupta
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops! Need to be more regular at the ranch, I guess!!
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
void method X()
{
String r = new String("abc");
String s = "abc";
r = r+1; //1
r = null; //2
s = s + r; //3
} //4
Hi ankur which String u r talking about is the String present in Heap memory that was created using statement String r = new String("abc");
Well if this is the string u r expecting it would be eligible for garabage collection at anytime after line marked with //1 is executed.
if u r talking about the String created in the String pool with
String s = "abc" ..Then it would be available for garbage collection only after class in which this method is declared is unloaded.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic