The garbage collector is called automatically when needed. Using gc() calls the garbage collector. I think, it makes only sense to use it if you remove objects in the loop. Then calling the garbage collector could help. Quoting from ?gc:
"[...] 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."
Calling gc() can be time consuming. I did a little test to check that:
library(microbenchmark)
library(ggplot2)
lst <- rep(list(rnorm(10000)), 30)
res <- microbenchmark(
for(i in seq_along(lst)) {
write.csv(lst[[i]], file="delme.csv")
gc()
},
for(i in seq(ll)) {
write.csv(lst[[i]], file="delme.csv")
})
levels(res$expr) <- c("with gc()","without gc()")
autoplot(res)

So it seems that calling gc() everytime is probably not a good idea. Of course it depends a lot on what you are doing in the loop.
Just a hunch: Garbage collection problems are not slowing your code down. You can probably optimize other parts of your code, e.g. using an *ply function instead of for loop can sometimes help.
Hope it helps,
alex
paste("C:/....", i, ".csv", sep=""))and alsox[[i]]instead ofx. Consider providing some more info of what you are doing in the loop, are you creating temporary objects and then remove them?istored data.