Remember that Java is pass by value. This means that the changes to "str" are lost after the method. sb.append() however is a method call so the value of sb changes. Then when sb is set to null, that's only the method's parameter reference. The main method still has a reference to the object.