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 about anonymous inner classes in java?
int a=1,b=10; System.out.println(a+b--);
When will we prefer to use set and list in java and why?
Where is the find and replace?
what are the major differences between jdk1.4 and jdk1.5?
2 Answers Cap Gemini, Crimson Logic, Infosys, TCS, Tenth Planet,
What is the protected method modifier?
Is java ee a framework?
What will happen if there is a default method conflict as mentioned above and we have specified the same signature method in the base class instead of overriding in the existing class ?
What is the use of set in java?
Can you make a constructor final in Java?
0 Answers SwanSoft Technologies,
What is a boolean expression in java?
How does serialization work