[R] memory storage explosion

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Mon Sep 2 08:47:54 CEST 2002


I guess this is becasuse you are returning a whole rpart fit, and so
really are using the memory.

Try just returning what you need from the rpart object.

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?

I think your diagnosis is an incorrect guess.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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