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
explain the difference between jdk and jvm?
what is mena by object block any what is the use of that
Why collection doesn’t extend cloneable and serializable interfaces?
What is method in research paper?
What is the purpose of assert keyword used in jdk1.4.x?
Explain about wait() method?
What is the effect of keeping a constructor private?
How an object is serialized in java?
How finally used under exception handling?
Is java ee a framework?
What are the states of thread in java?
What is a JAR file?
Define how can we find the actual size of an object on the heap?
What do you understand by private, protected and public?
What if I write static public void instead of public static void in java?