locked
C#-Garbage Collection RRS feed

  • Question

  • User2017388348 posted

    Dear All,

    QT-Why there are only 3 generations in garbage collection. why not g3,g4, etc.

    Please explain me or anybody have any link, Please provide me.

    Thanks,

    Sunday, June 10, 2018 6:59 PM

All replies

  • User36583972 posted


    Hi raushankarn,

    QT-Why there are only 3 generations in garbage collection. why not g3,g4, etc.

    As far as I know, this is a design patterns, if you create a mechanism yourself, you can define G3, G4, etc.


    the below generations of Heap:

    0 Generation (Zero): This generation holds short-lived objects, e.g., Temporary objects. GC initiates garbage collection process frequently in this generation.

    1 Generation (One): This generation is the buffer between short-lived and long-lived objects.

    2 Generation (Two): This generation holds long-lived objects like a static and global variable, that needs to be persisted for a certain amount of time. Objects which are not collected in generation Zero, are then moved to generation 1, such objects are known as survivors, similarly objects which are not collected in generation One, are then moved to generation 2 and from there onwards objects remain in the same generation.

    For more detailed, please see Fundamentals of Garbage Collection:
    https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals

    Best Regards,

    Yong Lu

    Monday, June 11, 2018 5:50 AM
  • User2017388348 posted

    Hi Yohaan,

    Thanks for your response,

    Your answer is correct but my question was, why heap only using Generation 0 to till 2. why not heap using generation 3 or 4 etc. I hope you can understand my question.

    Thanks.

    Monday, June 11, 2018 11:15 AM
  • User303363814 posted

    Why no G3 and G4?  Because everything is gone.  There is nothing to clean up.

    Monday, June 11, 2018 11:36 PM
  • User2017388348 posted

    Hi Paul,

    Why no G3 and G4?  Because everything is gone.  There is nothing to clean up.

    Thanks for your response.

    Nice answer.

    Thanks,

    Tuesday, June 12, 2018 7:17 AM