Java: setting a reference to null won't affect the object
问题 I've got a simple question. In this code below, why is s3's value still printed although I set it to null before. It seems gargbage collector won't get called. public class Test { public static void main(String[] args) { String s1 = "abc", s2 = "def", s3 = "ghj"; String sarr[] = {s1, s2, s3}; s3 = null; System.gc(); for(int i = 0; i < sarr.length; i++) { System.out.print(sarr[i] + " "); //prints abc def ghj } } } Any thoughts would be appreciated. 回答1: When you write: // Moved [] to make it