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 / bhudeep

Java provides us one method System.gc()to call garbage
collection forcefully.But by calling System.gc() will not
ensure you that the object will be garbage collected.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is advantage of java?

538


Why is singleton not thread safe?

647


Are maps ordered java?

504


How many bytes are there?

536


What is toarray method in java?

556






What are the 3 types of loops in java?

526


Can interface be private in java?

540


List any five features of java?

565


What is off heap memory?

542


What is a class in java?

578


Describe string intern() methodology

592


Do we have pointers in java?

524


Does java support Operator Overloading?

605


What is the purpose of encapsulation?

538


What is the transient keyword?

627