How to send a request to garbage collector?

Answer Posted / ashwani maddeshiya

static void gc() // Requests GC to run
static void runFinalization() // Requests finalizers to run

OR
mport java.util.*;

class GarbageCollectionDemo
{
public static void main(String s[]) throws Exception
{
// Get runtime environment
Runtime rt = Runtime.getRuntime();
System.out.println("Free memory before Garbage Collection = "+rt.freeMemory());

// Apply garbage collection
rt.gc();
System.out.println("Free memory after Garbage Collection = "+rt.freeMemory());
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is better- service oriented or batch oriented solutions?

1901


why java does not support unsigned keyword?

4735


What is the independent variable in an experiment?

759


Why Java doesn’t support multiple inheritance?

839


What is bifunction in java?

913


How to reverse a string in java?

800


Is there any difference between synchronized methods and synchronized statements?

825


Is age a discrete variable?

748


What is a flag value?

731


Explain about fail safe iterators in java?

808


What is the basic difference between string and stringbuffer object?

851


Is null a keyword in java?

756


What is __ init __ functions?

814


What is the base class of all classes?

777


What is the function of http?

791