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)
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With