I have a function that performs a stochastic simulation and writes results into a csv file.
I have a script:
When I do this for a large number of N, I get out of memory error. I don't understand why this is the case because I thought all variables from calling the function would get cleared at the end and free up the memory.
My workaround has been to run RunSingleSimulations(parameters, ~) individually and then combining the output file at the end. I never get out of memory error while running the function a single time. So I suppose there's some buildup of memory usage by calling it in a for loop, and would like some help understanding why and how to deal with it.