File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Q. on G.C Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Q. on G.C" Watch "Q. on G.C" New topic

Q. on G.C

Anuji Philip
Ranch Hand

Joined: Feb 25, 2002
Posts: 46
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

Joined: Mar 26, 2002
Posts: 262
I'm not completely sure, but I thought that only methods (and not member variables) could be declared with the native modifier?

Fun programming etcetera!
Kareem Qureshi
Ranch Hand

Joined: Mar 14, 2002
Posts: 102
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
Neelima Rao

Joined: Feb 24, 2002
Posts: 26
You can get information about garbage collection of String literals in this discussion:
I agree. Here's the link:
subject: Q. on G.C
jQuery in Action, 3rd edition