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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how many objects are eligible for Garbage collection

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I have doubt in this program

1. public class BettyAck{
2. public static void main(String argv[]){
3. BettyAck b =new BettyAck();
4. }
5. public BettyAck() {
6. Integer x = new Integer(10);
7. findOut(x);
8. Integer y = new Integer(99);
9. Integer z = y;
10. z = null;
11. findOut(y);
12. //here
13. }
14. public void findOut(Integer y){
15. y = null;
16.
17. }
18.}

my answer for this program is 3 objects are eligible for garbage collection.Is it correct or not?
Please anyone help me

with regards
prema
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
No object is eligible for GC.

This is the situation

a -> b -> object

When you make reference a point to null

a-> null
b -> object

So you can still get to the object with reference b
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
This problem was recently discussed here.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic