为什么 WeakReference 不是结构体?

Why isn't WeakReference a struct?

正如这篇文章所说:http://www.philosophicalgeek.com/2014/08/14/prefer-weakreferencet-to-weakreference/

If you are using WeakReference at all, it likely means you are somewhat memory conscious . In this case, allocating new WeakReference objects will contribute extra, unnecessary memory pressure.

所以在这种情况下,将其设为结构不是更有意义吗?并且在我们使用它时是不可变的,并摆脱 SetTarget()。

WeakReference and WeakReference<T> classes both have finalizers, which wouldn't be possible if they were structs.

如果确实有必要,您可以使用 weak variety of GCHandle 创建自己的自定义弱引用结构。 (我相信,尽管我不确定,WeakReferenceWeakReference<T> 在内部使用 GCHandle,尽管它们的终结器确保一切都被正确清理。您的自定义结构需要采取无需借助终结器即可自行清理。)