R is still in early stage and has few limitation that includes its memory management. R engine is not so smart to handle its memory efficiently. If you are using R studio, you can see two processes is running in task manager, they are –
Rstudio and Rsession
and if you are using GUI that comes with R engine, Rgui will be there. Its Rsession and Rgui that shows all CPU cycle and memory used.
Lets says, I have loaded IRIS data frame into the memory and create 3 subset of it and copy the iris data frame. My system memory looks like
R does not uses pointer of the object. When you try IRIS_Copy = IRIS, it create separate memory block for IRIS. It is advisable to use rm([object name]) function whenever object is unused. Whenever, we removed large object, it is also advisable to use gc(). The primary purpose of calling gc() is for the report on memory usage. However, it can be useful to call gc() after a large object has been removed, as this may prompt R to return memory to the operating system. R allocates space for vectors in multiples of 8 bytes.
We can check the memory available through memory.limit() and this works with windows OS only. We should be smart enough to use memory very efficiently and free the memory when the object is not in use.