top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Java: How the string objects in string constant pool garbage collected?

0 votes
353 views
Java: How the string objects in string constant pool garbage collected?
posted Mar 14, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

String a = new String("asd") -> "a" reference will be garbage collected, but is just a reference to "asd" and "asd" will be there forever.

answer Mar 16, 2016 by Shubham Singh
Similar Questions
0 votes

Will the String literal be garbage Collected?

  1. String str="ansh";
  2. str=null;
  3. //More code here

If no reference of String str is there after line 2, will this string become eligible for garbage collection or will it remains in String pool during the entire execution?

...