Memory usage after MailboxProcessor.Dispose()

let mutable run = true

[ for i in 0 .. 1_000_000 ->

   MailboxProcessor.Start(fun inbox ->

     async { while run do

               let! msg = inbox.Receive()

               printfn "agent %d got message '%s'" i msg } )] 
|> List.iter (fun x -> x.Post "Ping!"; x.Dispose()); run <- false;;

Code above consume memory up to 2GB but after done it memory of dotnet fsi stay 2GB even if I call GC.Collect (). Why?

let f () =
  
  
  [ for i in 0 .. 1_000_000 ->
  
     MailboxProcessor.Start(fun inbox ->
       let mutable run = true
       async { while run do
  
                 let! msg = inbox.Receive()
                 run <- false
                 printfn "agent %d got message '%s'" i msg } )] 
|> List.iter (fun x -> x.Post "Ping!"; x.Dispose()) 
f ()
System.GC.Collect ()

I change code for run explicit stopped but memory still grow.
I check memory via command:

tasklist /FI "IMAGENAME eq dotnet.exe"

Now I think reason not in leak but in reserved memory by dotnet for performace. Many times collect reduces value of memory process.

1 Like