There is a section on garbage collection in Advanced R.
You can force the garbage collector to run by calling gc() . Despite what you might have read elsewhere, there’s never any need to call gc() yourself. You may want to call gc() to ask R to return memory to your operating system, or for its side-effect of telling you how much memory is currently being used