[R] memory storage explosion

Saket Joshi joshi at engr.orst.edu
Tue Sep 3 04:30:42 CEST 2002


Hi,

I tried using 'for' loops and also tried explicit calls to gc() (infact
that is how I found out when and how much memory is being allocated and that it
is not getting freed).

Could this be a bug in R? If not so, the there must be a way to free this
memory used. Could you give me some idea as to how I can do that?

Thanks,
-Saket.


On Sun, 1 Sep 2002, Roger Peng wrote:

> You could make an explicit call to 'gc' to force a garbage collection
> (although I don't think this would really make a difference, just
> guessing).  Also, you might try using a 'for' loop instead of 'lapply' in
> your 'fgh' function.
>
> -roger
> _______________________________
> UCLA Department of Statistics
> rpeng at stat.ucla.edu
> http://www.stat.ucla.edu/~rpeng
>
> On Sun, 1 Sep 2002, Saket Joshi wrote:
>
> > Hi all,
> >
> > I am using R1.5.0 under unix.
> >
> > I have 2 data.frames x and yx. both have the same number of rows. I wrote
> > a function abc to do the following:
> >
> > abc <- function(x, zyx)
> > {
> > x[1] <- zyx   # zyx is a column of yx
> > rpart(x)
> > }
> >
> > Then I wrote another function fgh:
> >
> > fgh <- function()
> > {
> > yx <- ............... # yx created
> > x <- ................  # x created
> > lapply(yx, abc, x)
> > }
> >
> > when I ran function fgh at the prompt, the program started running out of
> > memory and the process running R gets killed. The reason for
> > the memory running out is that with every call to the abc function in the
> > implicit loop lapply, the memory equivalent to that of x is allocated in the
> > variable storage (Vcells). The trouble is that the memory allocated is not
> > freed when the function abc is run by lapply for the next element of yx
> > i.e. in the next loop.
> >
> > Since x takes up 25 MB of space and since yx has 126 columns, a lot of
> > memory space keeps getting allocated without being freed even when it is no
> > longer required.
> >
> > I wonder if there are any options that I should set so that the memory
> > allocated within a function is freed when the function is exited. But I am
> > not sure how to do that or else how to free the memory by any other way.
> >
> > Could someone tell me how I can avoid this memory explosion?
> >
> > Thanks in advance,
> > -Saket.
> >
> >
> >
> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> > Send "info", "help", or "[un]subscribe"
> > (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> >
>

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list