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
What is the difference between scrollbar and scrollpane?
What is the use of predicate in java 8?
What is method overloading and method overriding?
what is collatration?
Can you use this() and super() both in a constructor?
What is the largest data type in java?
How many bytes is a char in java?
When should the method invokelater() be used?
What initialize variables?
What is the difference between path and classpath variables?
What is :: operator in java 8?
List types of storage classes in java?
Explain tree set and its features?
Explain about assignment statement?
what is the difference between Object Based Language and Object Oriented Language?