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
When can you say a graph to be a tree?
What is a return in java?
What is a method header?
What is meant by vector class, dictionary class, hash table class, and property class?
What is time complexity algorithm?
Why heap memory is called heap?
What are the differences between checked exception and unchecked exception?
what do you mean by stream pipelining in java 8? Explain
What is treeset in java collection?
What is the difference between heap and stack memory?
what is the difference between a threads start() and run() methods? : Java thread
Is null a value?
How hashset works internally in java?
worst case complexities of Quick sort and Merge sort.
What is try-with-resources in java?