This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q. on G.C

 
Anuji Philip
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)void method2()
{
String s1 = "hello";
String s2 = "Pal";
s1 = s1+s2;// #5
}
Here after line #5 ,hello string get eligible for g.c, or never string literals get garbage collected?
2)Is it true that static and native members never get g.cted?
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not completely sure, but I thought that only methods (and not member variables) could be declared with the native modifier?
 
Kareem Qureshi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think "Hello" is eligible for gc after # 5 because since string s1 now refers to different string "hello" is left without any reference so it is eligible or gc.
please correct
kareem
 
Neelima Rao
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can get information about garbage collection of String literals in this discussion:
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=015183
HTH....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic