This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection" Watch "Garbage Collection" New topic

Garbage Collection

Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
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?


Select 1 correct option.

3.obj = null;
5.None of these.

Answer given is: option 5

Question: Why option 3 is not correct

Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
janki tangeda
Ranch Hand

Joined: Jun 07, 2005
Posts: 54
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

Joined: Nov 15, 2004
Posts: 1026
I agree. Here's the link:
subject: Garbage Collection
It's not a secret anymore!