I'm having a hard time figuring out how to free up memory by zeroing and garbage collecting objects in a function.
function runModel() d = generateData() d = 0 gc() end When I run runModel() in the REPL memory usage remains as if d is still stored in memory. Even if I do: for i in 1:5 d = generateData(); d = 0 gc() end Memory is not freed by the garbage collection. If I enter: julia> d = generateData(); julia> d = 0 julia> gc() Then memory from d is freed up. I've looked at this SO question: http://stackoverflow.com/questions/25871711/julia-garbage-collection-inside-functions-works-differently-than-in-global-spac but it doesn't provide any answers. Why is memory freed when run garbage collection is done in the global scope, but not in a function or for-loop?