• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Garbage Collection problem??

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


i think 2 objects r eligible 4 garbage collection(at line 4).

I'm a bit confuse,plz explain this garbage collection regarding in method return.



Thanks in advance.
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only one object.

3. X x = new X(); //create one. x references to it
4. X x2 = m1(x); //create one in m1 method. x2 references to it
5. X x4 = new X(); //create one. x4 references
6. x2 = x4; //x2 references to x4's object. x2 originally referenced object can be GC.
 
Ravinder Rana
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks 4 reply,
Wise Owen u r saying, X x=new X();//creat one
I think it creates two objects, then how one object eligible 4 garbage colln.

Plz clear it to me, I'm a bit confuse.



Thanks in advance.
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How many instances of X are created from line 3 to 5?
Can you explain why u think 2 objects 4 GC?
reply
    Bookmark Topic Watch Topic
  • New Topic