I was looking into some Java code from a large project and after a computational expensive loop that used an ArrayList
I saw this:
list.clear();
list = null;
I know that the Garbage Collector is automatically triggered when an object is not referenced anymore, so my question is this: does the above code de-references the object so as the GC would delete it later on? From my experience, clearing a list is actually the procedure of nulling all of its elements and nulling the list, de-references the object of it. Is this procedure preferred over leaving the object without any clearance? The above section of the code is followed by a large number of functions and calls, so if my assumption is correct and the list is effectively un-referenced, the GC will be activated earlier on and free up useful memory.