This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • 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
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

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.
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!