class App{
int[] a;
private void firstFunction(){
int[] b = {1, 2, 3, 4};
a = new int[4];
a = b;
}
private void secondFunction(){
for(int i=0; i<a.length; a++) System.out.println(a[i]);
}
}
Both a
and b
are pointers toward the same memory. When b
is out of scope, the allocated memory should be released and a
should become null, right? Or it is based on reference-counting approach, with b
being deleted but memory still exists?