Weak References
C# and Java both define weak references. If the only reference to an object is a weak reference, the object can be collected as garbage. Weak references are useful for referencing data that can easily be re-created and that should be freed if there is pressure for memory. Weak references are frequently used for cached data, where there is a performance improvement when the data is read from the cache but the data can be re-created if the cached information is collected.
The System.WeakReference class is used to create a weak reference. A weak reference is said to track an object, which is to say, maintain a weak association. There are two forms of weak reference, short-lived and long-lived. The difference is that long-lived weak ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access