•
Arrays are references!
•
Garbage collection reclaims arrays that can not be
accessed!
•
References are initialized to null
•
When done with a reference set it to null
public
classArrayExamples{public static void main( String args[] )
{int[] integerArray = new int[ 4 ];integerArray[ 1 ]
= 12integerArray = new int[ 2 ]; // Memory Leak - No!integerArray[ 1
] = 5;int[] aliasForArray =
integerArray;aliasForArray[ 1 ]
= 10;System.out.println(
integerArray[ 1 ] ); //Prints 10}
}
HEAP ALLOCATION
![]() |
integerArray[
1 ] = 12
|
|
integerArray = new int[ 2 ]; // Memory Leak - No!
![]() |
integerArray[ 1
] = 5;
![]() |
int[] aliasForArray =
integerArray;
![]() |
aliasForArray[ 1
] = 10;
![]() |
Memory
Problems in C/C++
Memory Leaks
Memory that program has allocated but can no longer
access int* trouble = new int( 5 );
![]() |






No comments:
Post a Comment