This program performs garbage collection.
Free memory in java virtual machine is
printed and then garbage collection is done
using gc method of RunTime class,
freeMemory method returns amount of free
memory in jvm, getRunTime method is used
to get reference of current RunTime object.
Java programming source code
EXAMPLE CODE
import java.util.* ;
class GarbageCollection
{
public static void main ( String []args) throws Exception
{
Runtime rs =Runtime. getRuntime() ;
System . out. println("Freememory in JVM before GarbageCollection = " + rs. freeMemory ()) ;
rs. gc() ;
System . out. println("Freememory in JVM after GarbageCollection = " + rs. freeMemory ()) ;
}
Obviously the amount of available after
garbage collection will be different on your
computer. Numbers are not important, what
is important is that amount of memory
available is more than before. You can use
this code in your program or projects which
uses large amount of garbage value and data.
Free memory in java virtual machine is
printed and then garbage collection is done
using gc method of RunTime class,
freeMemory method returns amount of free
memory in jvm, getRunTime method is used
to get reference of current RunTime object.
Java programming source code
EXAMPLE CODE
import java.util.* ;
class GarbageCollection
{
public static void main ( String []args) throws Exception
{
Runtime rs =Runtime. getRuntime() ;
System . out. println("Freememory in JVM before GarbageCollection = " + rs. freeMemory ()) ;
rs. gc() ;
System . out. println("Freememory in JVM after GarbageCollection = " + rs. freeMemory ()) ;
}
Obviously the amount of available after
garbage collection will be different on your
computer. Numbers are not important, what
is important is that amount of memory
available is more than before. You can use
this code in your program or projects which
uses large amount of garbage value and data.
-Shouvik Mitra
0 comments :
Post a Comment