none
How does generations help performance ? RRS feed

  • Question

  • i know that the Garbage Collector uses Generations.
    i also read about Generations : The objects that survive Generation 0 go to Generation 1 and  if survive again then go from generation 1 to 2.

    but how does that help performance ?
    is it because the objects that are in generation 1 and 2 are not checked again to see if they are garbage ? ( just guessing )
    Wednesday, December 3, 2008 3:30 PM

Answers

  • You are almost right:

    objects from generations 1 and 2 are more rarely checked by garbage collector, then those residing in generation 0.

    Vitaliy Liptchinsky http://dotnetframeworkplanet.blogspot.com/
    • Marked as answer by rodniko Thursday, December 4, 2008 12:27 PM
    Wednesday, December 3, 2008 6:15 PM
  • Yup, typical programs create a lot of temporary objects.  Especially strings.  They can be picked-off quickly in a gen 0 collection.  If they are still referenced when a gen 0 collection runs, it is more likely that they are actually longer-lived objects instead of temporary ones.  Move them to gen 1, don't bother checking too often if they are still referenced.  Less objects to check == faster collection.
    Hans Passant.
    • Marked as answer by rodniko Thursday, December 4, 2008 12:27 PM
    Wednesday, December 3, 2008 11:51 PM
    Moderator

All replies

  • You are almost right:

    objects from generations 1 and 2 are more rarely checked by garbage collector, then those residing in generation 0.

    Vitaliy Liptchinsky http://dotnetframeworkplanet.blogspot.com/
    • Marked as answer by rodniko Thursday, December 4, 2008 12:27 PM
    Wednesday, December 3, 2008 6:15 PM
  • Yup, typical programs create a lot of temporary objects.  Especially strings.  They can be picked-off quickly in a gen 0 collection.  If they are still referenced when a gen 0 collection runs, it is more likely that they are actually longer-lived objects instead of temporary ones.  Move them to gen 1, don't bother checking too often if they are still referenced.  Less objects to check == faster collection.
    Hans Passant.
    • Marked as answer by rodniko Thursday, December 4, 2008 12:27 PM
    Wednesday, December 3, 2008 11:51 PM
    Moderator