Page 1 of 1
About Question com.enthuware.ets.scjp.v6.2.426 :
Posted: Wed Nov 28, 2012 3:58 pm
by ETS User
I understood that strings were put in the string pool and therefore not GC'd?
Re: About Question com.enthuware.ets.scjp.v6.2.426 :
Posted: Thu Nov 29, 2012 7:37 am
by admin
Not all strings fall into that category. If you create a string using new e.g. new String("xyz"), there are actually two string objects created, one instantiated in a string pool (which cannot be GCed) and another one in the heap (which can be GCed).
HTH,
Paul.
Re: About Question com.enthuware.ets.scjp.v6.2.426 :
Posted: Sat Dec 22, 2012 6:50 am
by adrianoribeiro
Hi, we should not consider the "" as collectible?
thanks.
Re: About Question com.enthuware.ets.scjp.v6.2.426 :
Posted: Sat Dec 22, 2012 8:27 am
by admin
adrianoribeiro wrote:Hi, we should not consider the "" as collectible?
thanks.
That depends on whether it is a literal or now.
String s = ""; //not collectible.
String s = new String(""); //collectible.