• Post Reply Bookmark Topic Watch Topic
  • New Topic

Does a generational garbage collector have to visit all objects during a minor GC?  RSS feed

 
Swerrgy Smith
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I would like to know if a generational garbage collector visits all objects during a minor GC or it only visits the objects in the Young Generation?
If the answer is no, how can it do this? Because in my understanding, it has to start from a "root" and visit all reachable objects from this "root". There is no way it can knows in advance which objects are in the Young Generation and which objects are in Old Generation.

If the answer is yes, how it can be better than a traditional garbage collector while it also has to spend time to visit all objects.

Thank you very much.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is a Young Generation and an Old Generation? Those concepts have ceased to exist in recent versions of Java®.
If it is possible to release enough memory by visiting half the objects on the heap, then a GC can visit only half the objects. It does not matter whether a GC really operates like that, and that is something which you do not need to know. It may also vary from version to version and vendor to vendor.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swerrgy Smith wrote:
I would like to know if a generational garbage collector visits all objects during a minor GC or it only visits the objects in the Young Generation?
If the answer is no, how can it do this? Because in my understanding, it has to start from a "root" and visit all reachable objects from this "root". There is no way it can knows in advance which objects are in the Young Generation and which objects are in Old Generation.


As Campbell stated, this is merely an implementation detail, and not really important to know how... but... as an FYI...

Depending on the implementation, the JVM maintains a set of roots -- of objects in the young generation, that are referred from the tenure generation. Of course, to keep this set of roots somewhat up to date, there are code which are executed when code in the JVM runs. I don't know the full details of what is tracked when, nor do I know how accurate is this set of roots. Sorry.

Hope this helps,
Henry
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!