3
votes

If I open up fsi and paste the following:

[1..10000000];;
[1..10000000];;
[1..10000000];;
[1..10000000];;
[1..10000000];;
[1..10000000];;
[1..10000000];;
[1..10000000];;
[1..10000000];;

I get:

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

Same thing if I prefix with let x =. It seems that top level references continue to be held, no matter how inaccessible they may be. Is there any way to clean these things up, without losing the convenience of being able to step through your data? Right now I'm simply restarting to clean up, but it's inconvenient.

2
A bit pedantic, but that isn't a memory leak, its simply how the fsi functions. - N_A
@mydogisbox According to Wikipedia, "a memory leak may happen when an object is stored in memory but cannot be accessed by the running code". "How it functions" is, in this case, to leak memory. - Lamarth
Well if you execute the same code not in fsi.exe but in your own executable program it will behave the same way. - Petr
[<EntryPoint>] let main argv = [1..100000000] [1..100000000] [1..100000000] [1..100000000] [1..100000000] [1..100000000] [1..100000000] [1..100000000] [1..100000000] printfn "%A" argv 0 // return an integer exit code - Petr
It's malformed in comment, but essentially it pretty much the same code wrapped up in main function - Petr

2 Answers

2
votes

Since you are willing to use let x = [1..10000000] then use :

let mutable x = [1..10000000];; 

and to reuse the data memory use:

x <- [1..10000000];;  

and to release the data memory use:

x <- [];; 
2
votes

I don't think that there is a way to clean top level references in FSI. You can increase amount of memory that FSI can address using 64-but mode for F# Interactive process. In VisualStudio it is "Tools-Options-F# Tools->F# Interactive" settings