Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I "free" variables in Julia?

Tags:

julia

I'm coding a machine learning procedure that works with large datasets and some other related calculations. Since the datasets could be very large, some calculations result into very large matrices (for example 29,000 x 29,000 Array{Float64,2}), and they need large amounts of storage (RAM). Later in the procedure some elements (like the initial dataset) are not required anymore but they are still wasting memory space.

Is there a way to "free" variables at some moment? Or instead, is there a way to share some hard disk portion, something like swap space?

like image 759
David Avatar asked Jun 03 '14 22:06

David


People also ask

How do you clear a variable in Julia?

In Julia 0.6. You can remove the variable and free up it's memory by calling clear!() .

What is :: In Julia?

A return type can be specified in the function declaration using the :: operator. This converts the return value to the specified type. This function will always return an Int8 regardless of the types of x and y .

How do I clear my workspace in Julia?

You can clear the Workspace from the Console by pressing Ctrl+D to end Julia and Enter to start it again.


1 Answers

Just to wrap this up... typical approach is to overwrite objects that are consuming memory unnecessarily with ones that require very little memory. Taken from the FAQ (as linked 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 runs; you can force this to happen with gc().

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

    workspace()
like image 71
Kino Avatar answered Sep 18 '22 14:09

Kino