null

Does setting variable to null clear just the reference? [duplicate]

北城以北 提交于 2020-11-28 06:32:46
问题 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|

Does setting variable to null clear just the reference? [duplicate]

≡放荡痞女 提交于 2020-11-28 06:30:35
问题 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|

Does setting variable to null clear just the reference? [duplicate]

∥☆過路亽.° 提交于 2020-11-28 06:26:35
问题 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|