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 a map? What are the implementations of map?

822


Write a java program to generate fibonacci series ?

811


What is byte data type?

766


How you can force the garbage collection?

746


What are the various access specifiers for java classes?

782


How do you allocate memory to object?

729


How many bits are used to represent unicode, ascii, utf-16, and utf-8 characters in java programming?

798


can any body body expalin best definitions & best real time exaples for opps concepts.

2042


What do you mean by data type?

783


How does split work in java?

752


What’s the difference between the methods sleep() and wait()?

772


How can we create objects if we make the constructor private ?

745


What is the difference between a loader and a compiler?

747


What is the difference between final, finally and finalize() in java?

787


What is procedure writing?

697