how-to

Others

How to get free JVM heap memory

For reading free memory in Java Virtual Machine use this code:

/* -- create some instances in memory */
    
for ( int i = 0; i < 10000; i++ ) { JButton button = new JButton(); }
    
/* -- check free memory in heap memory */
    
System.out.println( Runtime.getRuntime().freeMemory() );
    
Runtime.getRuntime().gc();

System.out.println( Runtime.getRuntime().freeMemory() );