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


Please Help Members By Posting Answers For Below Questions

What is array length in java?

521


Explain inheritance in java?

553


Is list ordered in java?

538


Define jit compiler?

655


What is Major and importance difference between for and foreach loop ?

570






What is a stringbuilder?

506


What is the difference between && and & in java?

567


Is nan false?

531


What is an class?

591


Can arraylist hold different types java?

482


List any five features of java?

565


How we can generate random numbers in java?

605


What is meant by polymorphism?

532


Write a code to create a trigger to call a stored procedure

530


What is the difference between method and means?

572