Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which objects are eligible for Garbage Collection?

 
abhinav sinha
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following is a piece of code -

<code>

public class BettyAck {
public static void main(String argv[]){
BettyAck b =new BettyAck();
}
public BettyAck() {
Integer x = new Integer(10);
findOut(x);
Integer y = new Integer(99);
Integer z = y;
z = null;
findOut(y);
//here
}
public void findOut(Integer y){
y = null;

}

<\code>

I came to know that on the line " //here " in the above code,none of the objects will be eligible for garbage collection but I am not convinced with explanation given.Please can anyone explain me clearly why is it so?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What was the explanation given ?
Why were you not convinced by it ?
Which objects do you think are eligible for garbage collection ?
 
abhinav sinha
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not exactly remember the explanation because I could not exactly understand it.I feel both objects are eligible for garbage collection but I know thats not the correct answer.Please can you give me the correct and a lucid and simple explanation?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to show you've put some effort into finding the answer, such as searching for similar questions on these forums. BettyAck is a good search term.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic