Frequently Asked Questions

Frequently Asked Questions

Memory

Why do I get an out of memory error? (answered by Tianjing Zhao)

In Julia, when we run the same code repeatedly, the garbage collection works as follows:

Steps1. open2. create matrix3. repeat4.repeat...repeat...
Runningx = rand(10000,10000)x = rand(10000,10000)x = rand(10000,10000)...
Memory(MB)89.2866.81628.41628.41628.4

Note that Memory(MB) information are obtained from Task Manager(Win10), which shows total physical memory reserved by Julia. You can also check free memory by running versioninfo(verbose=true) or Sys.free_memory()/2^20.

From above table, when we create a matrix, it will definitely use memory, and when we repeat it for the first time (step 3), the memory doubled. But for the consecutive repeating (step 4,5...), the memory doesn't change.

So if you repeat your code for the first time, your will double the memory. In this situation, restarting kernel will solve the problem. Here is a trick to avoid double memory: change to garbage (step iii) and collect garbage via GC.gc()(step iv) before repeating. See below example:

Stepsi. openii. create matrixiii. set to zeroiv. collect garbagev. repeat
Runningx = rand(10000,10000)x=0GC.gc()x = rand(10000,10000)
Memory(MB)86.9865.1865.198.6861.6

Speed