So I'm currently working on a program that needs to be able to deal with a large amount of data stored in arrays and it needs a method to clear out everything in the array. For the below example, would this be a bad thing to do memory wise? I know the garbage collector would eventually clean it up for you but is there a reason why another method (e.g. a for loop and setting each value within to null) might be better than this?
Object[] objArray = new Object[n];
/*Do some stuff with objArray*/
objArray = new Object[n]
Otherwise, doing this will allow this operation to run in O(1) time vs a for loop which would take O(n).