The following is an MWE that illustrates my problem:
let f (n : int) : unit =
{1 .. n}
|> Seq.iter (fun s ->
// Do something memory intensive, without retaining anything
()
)
()
// First call
f 100
// Second call
{1 .. 10}
|> Seq.iter (fun s -> f 10)
Even though the end result of the two calls is the same, the first call performs much worse than the second call. The memory usage in the first call goes up to 95%, and the system slows down to a crawl. The memory usage of the second one never exceeds 50%.
Can someone please explain why, and how I should have foreseen it? Thanks in advance for your help.