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 method reference in java?

569


What is the purpose of declaring a variable as final?

492


Which is illegal identifier in java?

596


What two classes are used to read data only?

645


Can we create a class inside a class in java?

554






What is the super void?

465


Why Java doesn’t support multiple inheritance?

641


Differentiate between stringbuffer and string?

605


How do you get the length of a string in java?

526


What if static is removed from main method?

579


How to declare objects of a class ?

589


Can I overload to string method

977


How many types of array are there?

559


Is jdk required on each machine to run a java program?

762


Say any two properties in beans?

638