Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unit test IDisposable?

I'm working on a piece of library code around IDisposable. The managed path (via using) is easily testable. I'm wondering about the finalizer though: Is calling System.GC.Collect() sufficient to force the finalizer to run?

like image 320
David Schmitt Avatar asked Oct 29 '08 10:10

David Schmitt


1 Answers

No, the GC.Collect() call is asynchronous, you would also need to call this:

System.GC.WaitForPendingFinalizers();
like image 122
RickL Avatar answered Oct 20 '22 14:10

RickL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!