Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is it possible to find out how many objects are eligible for garbage collection?

 
Alex Pi
Greenhorn
Posts: 17
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to find out programmatically how many objects are eligible for garbage collection and print out their quantity?
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really, no. At least not in any way suitable for somebody posting in "Beginning Java". But why do you ask? Do you have a reason why you would need to do that in your application?
 
Alex Pi
Greenhorn
Posts: 17
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not for a real-life programming
I just wanted to find out some opportunity to check my SCJP 6 answers
I assumed, maybe there exists some real-time list of objects with attribute: this object is accessible or not accessible for GC.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex, I see from some of your other posts that you're concentrating on the certification exam. You'll definitely find questions about when objects become eligible for garbage collection on that exam, but those questions are simply designed to test your knowledge of how object references work in Java. However don't confuse the questions with anything related to real-life programming. Don't take the examples you see there to be examples of good Java code (they are often examples of bad Java code designed to test your knowledge) and don't take the questions to be questions which you will actually encounter when you are writing code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic