WeakReference Bug?

前端 未结 1 955
南旧
南旧 2021-01-13 08:36
[TestMethod]
public void Memory()
{
    var wr = new WeakReference(\"aaabbb\");
    Assert.IsTrue(wr.IsAlive);
    GC.Collect();
    GC.Collect();
    GC.Collect();
         


        
相关标签:
1条回答
  • 2021-01-13 09:03

    I can think of two possible reasons off the top of my head:

    1. You're running in debug. References in debug last longer than in release, and possibly longer than you might think.
    2. You have a reference to a string, which since it is a constant, is probably interned (ie not dynamically allocated), and will never be collected.
    0 讨论(0)
提交回复
热议问题