How to send a request to garbage collector?

Answers were Sorted based on User's Feedback



How to send a request to garbage collector?..

Answer / anjum rehbar khan

Yes we can send arequest to garbage collection by writing a
simple line of code:

System.gc();

OR

Runtime.gc();

But it is simply a request not a order to JVM
because Garbage collection is JVM dependent

Is This Answer Correct ?    8 Yes 0 No

How to send a request to garbage collector?..

Answer / uv

As far as I know,it is not required to call the garbage
collector.
It automatically and periodically removes the unused
objects by an algorithm known as "Mark and Sweep".

However, if we intentionally want to call it then the above
suggestions are perfect.
Anyone who feels that it is incorrect, please feel free to
correct me.

Is This Answer Correct ?    4 Yes 0 No

How to send a request to garbage collector?..

Answer / chinna

It's Runtime.getRuntime().gc()

Is This Answer Correct ?    3 Yes 0 No

How to send a request to garbage collector?..

Answer / 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

More Core Java Interview Questions

What is a java predicate?

0 Answers  


What is a Java Virtual Machine?

1 Answers  


What is the difference between public, private, protected, and friend access?

0 Answers   Amazon,


What is the statements?

0 Answers  


In what ways you can handle exception ?

3 Answers  






how do you store phone numbers using java collections

5 Answers   Bosch, IBAB,


Can keyword be used as identifier?

0 Answers  


What are MalformedURLException and UnknownHost Exceptions and whey they will be thrown?

2 Answers  


Which list is sorted in java?

0 Answers  


How to convert String into primitive datatype.

6 Answers  


What about main thread in java?

0 Answers  


abstract class A{ int list []=new int [100]; A(int x,int y){ rondom n=new rondom(); for (int i==;i<100;i++); list [i]=x+r.next int(y-x+1); abstract sort (); abstract binary sarch(int temp); class B extends A{

3 Answers  


Categories