Need explanation on variables and scopes

Can someone help me understand why you should always declare variables in the smallest scopes (EVEN if it's part of a loop). Let's say I have this code

int[] a;
for(int i=0; i<100; i++){
a= (Some new array);
**does other things**
}

Here, this way, I believe I am using less memory because I do not want to keep reinitialzating the array like this:

for(int i=0; i<100; i++){
int[] a= (Some new array);
**does other things**
}

However, it seems like the latter is the preferred method of the two? I believe calling and instantiating a new array can cost a lot of memory. Where am I wrong? (Because I'm pretty sure I am wrong on this)

Comments (0)