About Question com.enthuware.ets.scjp.v6.2.426 :
Moderator: admin
About Question com.enthuware.ets.scjp.v6.2.426 :
I understood that strings were put in the string pool and therefore not GC'd?
-
- Site Admin
- Posts: 10386
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.426 :
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.
HTH,
Paul.
-
- Posts: 1
- Joined: Fri Dec 21, 2012 9:51 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.426 :
Hi, we should not consider the "" as collectible?
thanks.
thanks.
-
- Site Admin
- Posts: 10386
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.426 :
That depends on whether it is a literal or now.adrianoribeiro wrote:Hi, we should not consider the "" as collectible?
thanks.
String s = ""; //not collectible.
String s = new String(""); //collectible.
Who is online
Users browsing this forum: No registered users and 5 guests