• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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.
 
I found some pretty shells, some sea glass and this lovely tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic