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

When would you use a static class?

571


What does it mean that a method or field is “static”?

543


Why is multiple inheritance not supported in java?

550


What happens when a thread cannot acquire a lock on an object in java programming?

539


What is the difference between stringbuffer and stringbuilder class?

558






Why there are some null interface in JAVA? What does it mean? Give some null interface in JAVA?

606


Explain try and catch keywords in java?

616


Explain about version control?

581


What is singleton class example?

582


What are the different types of constructor?

514


What is the difference between static and global variables and also define what are volatile variables?

543


What are controls and their different types in awt?

592


Why string is not a wrapper class?

636


What is java lang object?

521


What is string array?

568