I run JVM 1.5.0 (Mac OS X Default) and I control my Java program in Activity Monitor. I have the following:
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Date; public class MemoryTest { public static void memoryUsage() { System.out.println( Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() ); } public static void main( String[] args ) throws IOException { ArrayList<Date> list = new ArrayList<Date>(); for ( int i = 0; i < 5000000; i++ ) { list.add( new Date() ); }
}
So why isn't physical memory freed up even though the garbage collector seems to be working fine?
java garbage-collection memory-management memory-leaks
Jake Nov 27 '08 at 19:11 2008-11-27 19:11
source share