I am trying to write unit test using .NET 4 to ensure that an object can be collected from garbage after running some code. In Java, I would use assertGC to provide weak link collection. How can I write this type of test for .NET?
I tried to save the object WeakReferenceand call GC.Collect(), but, as expected, sometimes my object is collected, and sometimes not. Note that this is for unit test, not production code. I would not want GC.Collect () in my real code base.
I use C #, but the same answer will be useful for VB.NET as well.
source
share