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
How will you get the platform dependent values like line separator, path separator, etc., ?
What are pass by reference and pass by value?
What are different access specifiers in java? Explain
Can I extend singleton class in java?
What is an class?
Can inner class be public in java?
Explain the difference between a Thread and a Process.
What is overloading and overriding in java?
How can a gui component handle its own events?
What does 3 dots mean in java?
Is java 1.7 the same as java 7?
Which access specifier can be used with class ?
What is polymorphism and what are the types of it?
What are disadvantages of java?
What is the size of string?