Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clear memory allocated by R session (gc() doesnt help !) [duplicate]

Tags:

I am doing machine learning in large scale but after while my compute getting so slow because of R memory occupation.
I cleared my objects and also I tried gc() and the result:

           used  (Mb) gc trigger   (Mb)  max used   (Mb)
Ncells  4460452 231.5   15288838 1116.6  36599071 1954.7
Vcells 29572776 349.4  324509788 2712.9 350796378 3376.4

My task manager shows R session still allocated over 3GB of my memory and my computer is still slow.
How can I release the memory taken by R? (I don't want restart the pc)

like image 679
Cina Avatar asked Oct 31 '14 08:10

Cina


People also ask

Does gc () Clear memory?

GC automatically releases memory when an object is no longer used. It does this by tracking how many names point to each object, and when there are no names pointing to an object, it deletes that object. Despite what you might have read elsewhere, there's never any need to call gc() yourself.

How do I clear the memory in RStudio?

You can do both by restarting your R session in RStudio with the keyboard shortcut Ctrl+Shift+F10 which will totally clear your global environment of both objects and loaded packages.

Why is my R session using so much memory?

R uses more memory probably because of some copying of objects. Although these temporary copies get deleted, R still occupies the space. To give this memory back to the OS you can call the gc function. However, when the memory is needed, gc is called automatically.

How do I free unused memory in R?

You can force R to perform this check, and free the memory right away, by running the gc() command in R or going to Tools -> Memory -> Free Unused R Memory.


1 Answers

best solution i found is restarting R session. in R studio ctr+shft+f10

and if you dont want to save workspace

makeActiveBinding("refresh", function() { system(paste0(R.home(),"/bin/i386/R")); q("no") }, .GlobalEnv)

paste0(R.home(),"/bin/i386/R --no-save") #--save will save workspace

cheers.

like image 157
Cina Avatar answered Oct 04 '22 18:10

Cina