GC in Java Setter

Viewed 196

In a Java setter method that assigns a new Object to a field such as:

public class MyClass
{
     private String s;
     public void mySetter(String newS) {
          s = newS;
     }
}

Does the previous String s get garbage collected after mySetter is called or should I null out s before I assign it to the new value?

public class MyClass
{
     private String s;
     public void mySetter(String newS) {
          s = null;
          s = newS;
     }
}
4 Answers
Related