Note that there are some explanatory texts on larger screens.

plurals
  1. POMailboxProcessor.Dispose does not make object GC collectible
    text
    copied!<p>I am stuck with fixing my TFS tests runs for an F# project that uses MailboxProcessor. The problem is the following warning that I receive from the TFS test runner:</p> <blockquote> <p>System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain. This can happen if the test(s) started a thread but did not stop it. Make sure that all the threads started by the test(s) are stopped before completion.</p> </blockquote> <p>I guess the problem is caused by the MailboxProcessor. The following snippet demonstrates the problem (I run it from fsi):</p> <pre><code>open System.Threading open System type TestDisposable () = let cts = new CancellationTokenSource () let processMessage (inbox:MailboxProcessor&lt;int&gt;) = let rec loop n = async { let! msg = inbox.Receive () return! loop (n+msg) } loop 0 let agent = MailboxProcessor&lt;int&gt;.Start (processMessage, cts.Token) interface IDisposable with member this.Dispose () = (agent :&gt; IDisposable).Dispose () cts.Cancel () cts.Dispose () printfn "TestDisposable.Dispose called" do let weakTarget = use target = new TestDisposable () new WeakReference (target) GC.Collect() GC.WaitForPendingFinalizers() GC.WaitForFullGCComplete() |&gt; ignore GC.Collect() printfn "WeakTarget is alive: %b" weakTarget.IsAlive </code></pre> <p>I expect the output line to say that weakTarget is <strong>dead</strong>. But its <strong>alive</strong>. I think it indicates some memory leak. The question is what do I do wrong? And the second question is whether the GC problem is related to the TFS test runner problem.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload