I am running my code in R (under Windows) which involves a lot of in-memory data. I tried to use rm(list=ls()) to clean up memory, but seems the memory is still
Maybe you can try to use the function gc(). A call of gc() causes a garbage collection to take place. 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.
gc() also return a summary of the occupy memory.