Does setting variable to null clear just the reference? [duplicate]
问题 This question already has answers here : What is the difference between a variable, object, and reference? [duplicate] (5 answers) Closed 5 years ago . What happens if I do: Object obj = new Object(); obj = null; Does it remove the object from memory, or clear just the reference? More formally, consider the code: Object obj = new Object(); Object temp = obj; obj = null; Why is temp still not null ? Shouldn't it have been removed from memory? 回答1: In your first example: obj -------> |OBJECT|