I'm running a complex computation (a [Markov chain model](https://en.wikipedia.org/wiki/Markov_chain))

```
let memoize f =
    let cache = new ConcurrentDictionary<'key,'value>()
    cache, fun x -> cache.GetOrAdd(x, Func<'key, 'value>f)

```

to cache intermediate results of multiple functions. The overall structure is something like this

```
module Foo =
    [...]
    let _, foo' = memoize foo

module Bar =
    [...]
    let _, bar' = memoize bar 

module Main = 
    open Foo
    open Bar
    [...]
    let result =
        foobar (foo' a) (bar' b)

```

Typically I run this once and then the program terminates, but it's obviously not nice to not clean up those cache dictionaries. Also, I sometimes need to call the model for many different inputs and then I quickly run into memory issues. What's the best way to clean up multiple caches at once?

**Edit**

A mentioned in the comments, it would of course be possible to collect all caches into a list. But I'd have to box the dictionaries and it doesn't seem nice to me. Is there a better (overall) strategy?