Free memory result should indicate whether Garbage collector has run : Garbage Collection « Java Source And Data Type « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Java Source And Data Type » Garbage Collection 
1.27.7.Free memory result should indicate whether Garbage collector has run
import java.util.Date;
   
   public class MainClass {
      public static void main(String [] args) {
         Runtime rt = Runtime.getRuntime();
         System.out.println("Total JVM memory: " + rt.totalMemory());
         System.out.println("Before Memory = " + rt.freeMemory());
         Date d = null;
         for(int i = 0;i<10000;i++) {
            d = new Date();
            d = null;
        }
        System.out.println("After Memory = " + rt.freeMemory());
        rt.gc();   // an alternate to System.gc()
        System.out.println("After GC Memory = " + rt.freeMemory());
     }
  }
1.27.Garbage Collection
1.27.1.JVM Garbage Collection
1.27.2.How to Cause Leaks in a Garbage Collection System
1.27.3.Avoiding the memory leak
1.27.4.To remove a reference to an object is to set the reference variable to null.
1.27.5.Reassigning a Reference Variable to remove a reference to an object
1.27.6.If an object is returned from the method, its reference might be assigned to a reference variable;
1.27.7.Free memory result should indicate whether Garbage collector has run
1.27.8.An Example of Garbage Collection in Action
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.