permaculture playing cards*
The moose likes Beginning Java and the fly likes is it possible to find out how many objects are eligible for garbage collection? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "is it possible to find out how many objects are eligible for garbage collection?" Watch "is it possible to find out how many objects are eligible for garbage collection?" New topic
Author

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

Alex Pi
Greenhorn

Joined: Jan 08, 2013
Posts: 17

Is it possible to find out programmatically how many objects are eligible for garbage collection and print out their quantity?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Jan 08, 2013
Posts: 17

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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.
 
GeeCON Prague 2014
 
subject: is it possible to find out how many objects are eligible for garbage collection?