• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Island objects : Objects elegible to Garbage collection  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Garbage collection question



Hi Java Gys,

So, I need to know how many objects are elegible to garbage collection

Look this code.

I am confuse a lot!!!

I think this question only java expert can anwer it !

Help me please.



 
Ranch Hand
Posts: 58
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe only one object created at line 8, Alpha alpha1 = new Alpha(); will be eligible for GC after line 18 but before main() returns.





 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sebanti Sanyal wrote:I believe only one object created at line 8, Alpha alpha1 = new Alpha(); will be eligible for GC after line 18 but before main() returns.







Hi, I thought 2 objects would be eligible for GC, objects referenced by 'alpha1' and 'beta1'.
But your explanation also makes sence, since 'alpha1.b2' is a static reference, it means class 'Alpha' still can get to object referenced by 'beta1'.
But I'm still in doubt... Carlos, do you happen to have the answer for that question? so that we would know for sure...

Thanks.
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only one object reffered by alpha1 will be eligible for GC.
Object reffered by beta1 can be reached by Alpha.b1 (static reference lives in stack)
Object reffered by beta2 can be reached through b2 in alpha2.
Object reffered by alpha2 is reachable with no big trick.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!