Thursday, May 3, 2012

Coding for Garbage Collection in Java



import java.util.*;
public class Garbagecoll 
{
public static void main(String[] args) 
{
int a=100,b=200,c=0;
c=a+b;
System.out.println(c);
     Runtime runobj =  Runtime.getRuntime();
     System.out.println("Free memory in Java Virtual Machine before Garbage Collection = "+runobj.freeMemory());
     runobj.gc();
     System.out.println("Free memory in Java Virtual Machine after Garbage Collection = "+runobj.freeMemory());
}
}

No comments:

Post a Comment

Followers