• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Garbage collection

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm doing the practice exam at the Sun Learning center. Here is one of the questions.
When is the object created at line 3 eligible for garbage colection?
a. It is eligible after line 7
b. It is eligible after line 8
c. It is eligible after line 9
d. It is not eligible for garbage collection in this method.

1. public class TipTop {
2. public String tipper() {
3. Object tip = new Object();
4. String[] top = new String[2];
5. top[0] = "this";
6. top[1] = "that";
7. tip = top[1];
8. top[1] = top[0];
9. tip = null;
10. return top[0];
11. }
12. }
The answer I entered is C. But the site says that the correct answer is A because there are no valid references left to the object. Am i missing something. Or is it because tip now refers to a different object in line 8.
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An object becomes eligible for gc when no references exist on an object, in line 7 the only reference on the object is removed when tip is reset to a reference another object!
 
Paul Ze
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks that is what i thought as i was writting the first post...check out my other question on local variables
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic