Mark and Sweep とは?
mark and sweep は、2 つのフェーズで動作する garbage collection の手法です。まずルート参照からたどってまだ到達可能なオブジェクトをすべてマークし、次にメモリを掃引してマークされずに残ったオブジェクトをすべて回収します。参照をたどるため、参照カウントでは回収できない循環構造も回収できます。トレードオフは、heap を定期的に走査する回収パスです。
なぜ重要か
mark and sweep はメモリを自動的に回収し、参照の循環も扱えるため、プログラマを手動の解放から解放します。その一時停止と走査コストが、generational collection のような改良を後押ししました。
関連ガイド
What Is Generational Garbage Collection?Generational garbage collection groups objects by age and collects short-lived young objects more often than…
What Is Reference Counting?Reference counting tracks how many references point to an object and frees it automatically when that count d…
What Is a Weak Reference?A weak reference points to an object without keeping it alive, so the object can still be collected and the r…