• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another Exercise regarding Garbage Collection:

 
Thomas Markl
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Float f = new Float(3.5f);
Float f = new Float(3.0f);
f = null;
f= null;
When is object referenced f eligable for g.c?
How many objects are eligable for g.c.
I think there are 2 objects eligable for g.c.
First the Float(3.5f) and then the last reference
Of f which is Float(3.0f).
Is that correct? What is the earliest point when
f is eligable for g.c. is it line 3?
Appreciate your answers.
Thomas
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean to name your references as f1 and f2... you have them both named as f???
 
Thomas Markl
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The references are both "f" in this question.
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Float f = new Float(3.5f);
Float f = new Float(3.0f);
f = null;
f= null;

Ok, just trying to make sure I understand. Since you can't declare the same variable twice, I think you mean...

Is that correct? If so, then I believe your first object (3.5) is eligible for gc at line 4, and your second object (3.0) is eligible at line 5.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The references are both "f" in this question.
As Blake implied, such a program fragment would produce a compile-time error.
Where did you find this example?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic