If I use "Array_Name[] = NULL", does the garbage collector of java collect the rest of the array?
2 Answers
Only if Array_Name had actually been referencing an array to begin with. And only if there are no other references to the array. And it will reclaim only those elements of the array which aren't referenced by anything outside of the array. And it will only do so when it feels like getting around to it :-)
(The syntax Array_Name[] = NULL isn't really meaningful. But I'm assuming you'd done something like:
Foo[] Array_Name = new Foo[n];
//...
Array_Name = null; // Note the lowercase "null"
This might make the array a proper target for garbage collection, given the conditions I described above.)
I agree with everything Dan mentioned above but you can actually trigger garbage collection manually by calling System.gc(). Of course as mentioned this will only collect objects that are no longer referenced by anything else.
Array_Name[] = NULLyou meanArray_Name = null, right?arrayName = null... style is important too.