<div dir="ltr">Hi chessai,<div><br></div><div>I'm not an expert on this but I think the idea is the following.</div><div>The more generations you have, the lower the frequency of the oldest generation getting garbage collected.</div><div><br></div><div>Here's why:</div><div>Each generation gets collected when it gets full. Anything that remains alive is then promoted to the next generation.</div><div>Because we expect heap objects to skew towards being short-lived, older generations will promote fewer and fewer objects into the next one.</div><div>This leads to a pattern where the youngest generation gets collected quite frequently, and each following generation gets collected less and less frequently.</div><div><br></div><div>This then means that the oldest generation is quite likely to contain many objects that are dead but not yet collected. This leads to higher than necessary memory usage. </div><div>Though there's positives too as you will have to run an expensive major collection less often.</div><div>If your application runs for long enough though, the oldest gen will eventually be collected. So I guess that's what this is referring to?</div><div>If you pick a high -G value, then expect to wait for a while before your oldest generation gets GC'd.</div><div><br></div><div>"long time" here is likely relative to the exact amount of generations you pick, but also your allocation patterns, etc.</div><div><br></div><div>Hope that helps!</div><div><br></div><div>Cheers,</div><div>Teo</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 20, 2024 at 7:32 PM chessai <<a href="mailto:chessai1996@gmail.com">chessai1996@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">The docs for -G state:<div dir="auto"><br></div><div dir="auto"><div dir="auto">```</div><div dir="auto">... Anything larger than about 4 is probably not a good idea unless your program runs for a *long* time, because the oldest generation will hardly ever get collected.</div><div dir="auto">```</div><div dir="auto"><br></div><div dir="auto">What is a "*long*" time?</div></div></div>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
</blockquote></div>