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 / namita
First We cannot force the garbage collection to garbage the
object. Garbage collection can never be forced.
So by calling System.gc() will not ensure you that the
object will be garbage collected.
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Write a factorial program using recursion in java?
In how many ways we can do synchronization in java?
What is the purpose of default constructor?
What is a functional interface?
What is <> used for in java?
How many bits are in a sentence?
Which method cannot be overridden in java?
Can bool be null?
Can you instantiate the math class?
How is abstraction implemented in java ?
What is difference between array and arraylist in java?
Implement a stack with push (), pop() and min() in O(1) time.
What is the multi-catch block in java?
What is an anonymous class in java?
What is the difference between JDBC 1.0 and JDBC 2.0?