How can I β€œfree” variables in Julia?

I am coding a machine learning procedure that works with large datasets and some other related computations. Since the data sets can be very large, some calculations lead to very large matrices (for example, 29,000 x 29,000 Array {Float64,2}), and they need large amounts of memory (RAM). Later in the procedure, some elements (for example, the original data set) are no longer required, but they still lose memory space.

Is there a way to β€œfree” variables at some point? Or is there instead a way to share part of the hard drive, something like swap space?

+7
julia-lang
source share
2 answers

Just to wrap it ... a typical approach is to overwrite objects that consume memory without the need for those that require very little memory. Taken from the FAQ (as stated above):

For example, if A is a gigabyte-sized array that you no longer need, you can free the memory with A = 0. The memory will be released the next time the garbage collector is started; you can make this happen with gc ().

If you want to create a new workspace (i.e. clear all variables), this is done with

workspace() 
+5
source share

You can also run the Julia garbage collector (to remove stuff that will eventually be deleted): gc ()

0
source share

All Articles