Hi: I am doing a MCMC algorithm which is well known to consume much computer memory. And I have a problem everytime I run my R program. It stopped at certain iteration and says "can not allocate a vector of 19 kb". It seems that the computer's memory has been exhausted. However, it is said that after each iteration the objects (such as a huge matrix) can be set to NULL. And the memory will be released so the program will consume as much memory as before. I wonder how to do that, that is, set the object to be NULL. Say, A is a matrix in each iteration. I just need to write A<-NULL ?? And this approach really works? Thank you very much! liu _______________________________ Declare Yourself - Register online to vote today!
Setting A <- NULL doesn't immediately release the memory, the memory is actually released in gc(), which R calls for you at some "random" time. In situations like this I explicitely call gc() and do not wait for R to do this, e.g A <- NULL; gc() Hope this helps, Vadim> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of yyan liu > Sent: Monday, October 11, 2004 11:55 AM > To: r-help at stat.math.ethz.ch > Subject: [R] memory in R > > Hi: > I am doing a MCMC algorithm which is well known to consume > much computer memory. And I have a problem everytime I run my > R program. It stopped at certain iteration and says "can not > allocate a vector of 19 kb". > It seems that the computer's memory has been exhausted. > However, it is said that after each iteration the objects > (such as a huge matrix) can be set to NULL. And the memory > will be released so the program will consume as much memory > as before. I wonder how to do that, that is, set the object > to be NULL. Say, A is a matrix in each iteration. I just need > to write A<-NULL ?? And this approach really works? > Thank you very much! > > liu > > > > _______________________________ > > Declare Yourself - Register online to vote today! > > ______________________________________________ > 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 >
yyan liu <zhliur <at> yahoo.com> writes: : : Hi: : I am doing a MCMC algorithm which is well known to : consume much computer memory. And I have a problem : everytime I run my R program. It stopped at certain : iteration and says "can not allocate a vector of 19 : kb". : It seems that the computer's memory has been : exhausted. However, it is said that after each : iteration the objects (such as a huge matrix) can be : set to NULL. And the memory will be released so the : program will consume as much memory as before. I : wonder how to do that, that is, set the object to be : NULL. Say, A is a matrix in each iteration. I just : need to write A<-NULL ?? And this approach really : works? : Thank you very much! : : liu Instead of, or in addition to, fighting with garbage collection, you might be able to find some combo of the command line options that allow you to run straight way. See ?Memory and play with the various options to R such as: --min-vsize=400M --min-nsize=6M