File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Q. on G.C" Watch "Q. on G.C" New topic
Author

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
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

Joined: Feb 24, 2002
Posts: 26
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....
 
jQuery in Action, 2nd edition
 
subject: Q. on G.C
 
Similar Threads
How many String Object are created in the following code ??
how can you modify a String?
Strings
String replace method
Guarenteeing G.C part