参照カウントとは何か?
参照カウントはメモリ管理の手法で、各オブジェクトをいくつの参照が指しているかのカウントを保持し、新しい参照で増やし、参照がなくなると減らします。カウントがゼロに達すると、オブジェクトは直ちに解放されます。メモリを速やかに回収しますが、互いに参照し合うオブジェクトの循環は回収できません。
なぜ重要か
参照カウントは別途の回収パスなしで決定論的なクリーンアップを提供し、速やかに解放されるべきリソースに適しています。その盲点は参照の循環であり、それを断ち切るためにweak referenceが存在します。
関連ガイド
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…
What Is Ownership in Memory Management?Ownership is a model where each resource has a single owning variable responsible for freeing it, making clea…
What Is Mark and Sweep?Mark and sweep is a garbage collection algorithm that marks all reachable objects, then sweeps away the unmar…