• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection

 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following code snippet:

void mymethod()
{
Object obj = new Object();
// 1 insert code here
}

What can be inserted at // 1, which will destroy the object refered to by obj?

Options

Select 1 correct option.

1.obj.destroy();
2.System.getRuntim().gc();
3.obj = null;
4.obj.finalize()
5.None of these.


Answer given is: option 5

Question: Why option 3 is not correct
 
janki tangeda
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We cannot force an object to be destroyed or garbage collected.
obj = null;
//makes the object eligible for garbage collection but doesn't destroy it.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic