• 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
  • 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

Garbage Collection- query

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,

Can anyone please help me out if this is right.

Suppose
Class A{ B b}
Class B{
A a
public static void main(String args[])

A aa = new A();
B bb = new B();
aa = null;'

At this point how many objects are gc. My understanding says one ie aa. Can anyone comment on this please


}
 
Ranch Hand
Posts: 82
Eclipse IDE Spring Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes,I think only one object of Class-A is eligible for Garbage Collection....

The other instance of B is still referenced by main method...


Thanks
Don,Red..
 
Mushraf Khan
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,

yes object aa gets garbage collected but life of all variable('s) or Object('s) is depends on "{}" <-- so may be all gets garbage collected..

Thanking you.
 
Ranch Hand
Posts: 58
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amey Ambulgekar wrote:hello,

yes object aa gets garbage collected but life of all variable('s) or Object('s) is depends on "{}" <-- so may be all gets garbage collected..

Thanking you.


But the question refers to the context after aa = null; and before the closing brace of main.Only one object,initially referred by aa is eligible for GC here.
 
Bring out your dead! Or a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic