弱参照とは何か?
弱参照は、オブジェクトの参照カウントに寄与したり、他の方法でそれが回収されるのを妨げたりすることなくオブジェクトを指します。最後の強参照がなくなると、弱参照が残っていてもオブジェクトは解放され得て、それらの参照は対象が消えたことを報告します。これにより、コードはオブジェクトを所有せずに観察できます。
なぜ重要か
弱参照は、参照カウントのもとで親子の逆ポインタのようにメモリをリークさせてしまう参照の循環を断ち切ります。また、自らエントリを生かし続けるべきでないキャッシュを実現します。
関連ガイド
What Is Reference Counting?Reference counting tracks how many references point to an object and frees it automatically when that count d…
What Is Mark and Sweep?Mark and sweep is a garbage collection algorithm that marks all reachable objects, then sweeps away the unmar…
What Is Ownership in Memory Management?Ownership is a model where each resource has a single owning variable responsible for freeing it, making clea…