[R] removing of memory - optim()?

Spencer Graves spencer.graves at pdf.com
Sat Mar 11 21:59:27 CET 2006

	  1.  Do you include "gc" (garbage collection) in your loop.  If not, I 
suggest you add that.

	  2.  If including "gc" in the loop does NOT fix the problem, I suggest 
you store the output of "gc" to track how it changes.  With luck, this 
might allow you to experiment with modifications of your calls to 
"optim".  If you can perform such experiments, then you might be able to 
identify just what is causing your memory to disappear.

	  3.  Have you tried running this job in batch mode?  This would allow 
you to run through the loop a certain number of times, store the results 
to that point, exit, then restart R and do it again.  I'm not clear on 
how to do this, but RSiteSearch("Running R in Batch mode") just produce 
83 hits for me, one of which was "An Introduction to R", which included 
instructions on how to do that.

	  4.  If you'd like more help from this listserve, PLEASE do read the 
posting guide! "www.R-project.org/posting-guide.html" especially the 
part about including a very brief but self-contained example of 
something you've tried that seemed like it should do what you want but 
didn't.  Also please include the output of 'sessionInfo()' so others can 
see what you are using.  In particular, if you are NOT using the latest 
version of R and of any packages you use, please upgrade first before 
wasting people's time trying to solve problems that may already have 
been solved.

	  hope this helps,
	  spencer graves	

Marcel Prokopczuk wrote:

> Dear all,
> I have the following problem: I am using Windows XP as OS and have a R
> program which uses optim() in a loop. Although I overwrite every variable in
> the loop the memory R is using is increasing until my system breaks down
> because the swap file is getting just to big. I suspect that optim() is
> creating some variables which are not deleted automatically. So I tried to
> do the following: every 10th loop or so, I save the variables I want to
> keep, delete the memory with rm(list=ls(all=TRUE)), and load back the data I
> saved before. But this is also not working. rm(list=ls(all=TRUE)) does not
> delete everything (I can see in the Task Manager of Windows that the memory
> occupied by the Rgui process stays huge).
> Does anybody had similar problems and/or know how to solve it. Thanks in
> advance for your help.
> Marcel
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

More information about the R-help mailing list