.Net 4 MemoryCache Leaks with Concurrent Garbage Collection

前端 未结 4 553
刺人心
刺人心 2021-01-30 13:24

I\'m using the new MemoryCache in .Net 4, with a max cache size limit in MB (I\'ve tested it set between 10 and 200MB, on systems with between 1.75 and 8GB of memory). I don\'t

4条回答
  •  遥遥无期
    2021-01-30 14:11

    You can "force" a garbage collection right after the problematic method and see if the problem reproduces executing:

    System.Threading.Thread.Sleep(200);
    GC.Collect();
    GC.WaitForPendingFinalizers();
    

    right at the end of the method (make sure that you free any handles to reference objects and null them out). If this prevents memory leakage, and then yes, there may be a runtime bug.

提交回复
热议问题