How to send a request to garbage collector?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
What is a parameter in matrices?
Can we declare main () method as non static?
How would overload a function based on return type?
Explain different ways of passing arguments to sub-routine?
how to open and edit XML file in Weblogic???
What is clipping and repainting and what is the relation between them?
What do you mean by composition in java?
What does function identity () do?
What is a java object and java application?
Hi Friends, can u give me Real Time example for interface and abstract class.(With Banking Example)
Difference between JVM and JRE?
Same common question what is Map,Set,HashMap,List????