public class Garbage
{
int a=0;
public void add()
{
int c=10+20;
System.out.println(c);
System.out.println(a);
}
public static void main(String args[])
{
Garbage obj=new Garbage();
System.gc();
System.out.println("Garbage Collected");
obj.add();
}
}
Above is a code in java used for garbage collection. object
obj has been created for the class Garbage and system.gc
method is called. Then using that object add method is
called.System.gc method if called the obj should be garbage
collected?
Answer Posted / bhudeep
Java provides us one method System.gc()to call garbage
collection forcefully.But by calling System.gc() will not
ensure you that the object will be garbage collected.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is double checked locking in singleton?
Enlist few advantages of inheritance?
What is exception propagation?
What are the advantages of unicode?
Can a private method be declared as static?
What does i ++ mean in Java?
What are inbuilt functions?
What is the difference between final, finally and finalize() in java?
What ide should I use for java?
What is the major drawback of internal iteration over external iteration?
What is the purpose of static keyword in java?
What is super in java?
How you can force the garbage collection?
Hi Anyone know the model / questions of the Federal bank sample questions for the post of Specialist Officers - Programmers. Please post if anyone have..
Can we write any code after throw statement?