I had learned that JVM will collect only the freed memory location during the garbage collection..That is if an object had a reference, then it will not be collected...
My doubt is, will the JVM collect all the used location whenever it goes out of the method..That is .
public void aa(){
ArrayList list = new ArrayList();
for (int i = 0; i < 1000000; i++) {
list .add(i);
}
}
when will the memory allocated for "list" will be collected by JVM..Will it be collected when moving out of the function aa()..