I'm a little confused with the following scenario.
If there is an array created like so:
Declaration:
int[] array1;
Instantiation:
array1 = new int[500];
But then, later on, I no longer require 500 elements, so I simply create a new array with the new size, like so:
array1 = new int[50]
There are various references around the code that access this array, like so:
for (x=0;x<array1.length;x++){
array1[x]+someValue
}
What happens to the memmory where the other 450 elements were? The array itself is still 'alive' is it not because I still have lots of references to it's name, so it can't be GC'd, so I'm a little confused how the GC'd works in this case.
Note I know that I should have used an arrayList in order to re-size, unfortunately, this isn't an option for me now as it would be a ton of work to change my code (18 classes in size) so I want to stick to array's at least for this project and manage them as best I can.