I have an Android application where I allocate large arrays, fill them up, and throw them into buffers. After doing this, the arrays are lying around, doing nothing. Would setting them to null theoretically improve the performance of my app, or is the effect negligible/nonexistent?
1 Answer
Generally no, setting the array to null will not improve performance or memory use in any way.
The garbage collector will free up the memory when it decides that the object is no longer accessible. Explicitly setting a reference to null is a good signal to the garbage collector that the object is free-able, but if those arrays are already no longer being referenced anyway (because, say, their containing object is no longer referenced) then explicitly setting it to null won't make the garbage collection happen any more quickly.
1 Comment
zgc7009
Just adding to this already good answer; just because you set the array itself to null doesn't mean the contents of the array just disappear. They are still in memory and still have to be GC'ed just like when they were part of the array. They just aren't referenced by the array any longer, but since the array is longer being referenced it is redundant.