Forcing garbage collection to run in R with the gc() command

Viewed 32929

Periodically I program sloppily. Ok, I program sloppily all the time, but sometimes that catches up with me in the form of out of memory errors. I start exercising a little discipline in deleting objects with the rm() command and things get better. I see mixed messages online about whether I should explicitly call gc() after deleting large data objects. Some say that before R returns a memory error it will run gc() while others say that manually forcing gc is a good idea.

Should I run gc() after deleting large objects in order to ensure maximum memory availability?

6 Answers
Related