The method is about like this :
public void testGc() {
char c[] = new char[1024*1024*100] // Allocate 100M memory
System.gc();
}
But after the method returns, the memory allocated won't be free.
The method is about like this :
public void testGc() {
char c[] = new char[1024*1024*100] // Allocate 100M memory
System.gc();
}
But after the method returns, the memory allocated won't be free.
First of, you still have a reference so it won't be freed.
second: calling System.gc()
won't free the memory instantly. It just kindly asks the garbage collector if it could clean up.