growing process size in simulation
Luke Tierney
luke@stat.uiowa.edu
Fri, 11 Oct 2002 20:57:23 -0500 (CDT)
On 11 Oct 2002, Peter Dalgaard BSA wrote:
> Achim Zeileis <zeileis@ci.tuwien.ac.at> writes:
>
> > I came across this in a simulation I ran under 1.6.0: If I do something
> > like
> >
> > R> x <- rnorm(10)
> > R> rval <- NULL
> > R> for(i in 1:100000) rval <- t.test(x)$p.value
> >
> > then the process size remains at about 14M under 1.5.1, but it seems to
> > be almost linearly growing up to more than 100M under 1.6.0.
> >
> > I know that the above simulation is nonsense, but it was the simplest I
> > could come up with to reproduce the behaviour. It doesn't depend on
> > t.test, if I use wilcox.test(x)$p.value the same happens...
>
> Argh. Confirmed. One interesting clue is that R itself doesn't seem to
> know about this:
>
> for(i in 1:50000) {
> rval <- t.test(x)$p.value
> if (i %% 10000 == 0) print(gc())
> }
>
> used (Mb) gc trigger (Mb)
> Ncells 208343 5.6 407500 10.9
> Vcells 64656 0.5 786432 6.0
> used (Mb) gc trigger (Mb)
> Ncells 208343 5.6 407500 10.9
> Vcells 64656 0.5 786432 6.0
> used (Mb) gc trigger (Mb)
> Ncells 208343 5.6 407500 10.9
> Vcells 64656 0.5 786432 6.0
> used (Mb) gc trigger (Mb)
> Ncells 208343 5.6 407500 10.9
> Vcells 64656 0.5 786432 6.0
> used (Mb) gc trigger (Mb)
> Ncells 208343 5.6 407500 10.9
> Vcells 64656 0.5 786432 6.0
>
> ...but the memory footprint is still growing.
>
>
It looks to me like something in deparse (which gets called in
t.test.default) may be the culprit:
for(i in 1:100000) rval <- deparse("x")
exhibits the same behavior.
In running under gdb it looks like deparse("x") results in the call
sequence
deparse1WithCutoff->deparse2->deparse2buff->print2buff->R_AllocStringBuffer
and malloc is called in R_AllocStringBuffer to create the buffer. The
allocation is stored into a local structure variable in
deparse1WithCutoff and I think is not being free'd before
deparse1WithCutoff exits.
luke
--
Luke Tierney
University of Iowa Phone: 319-335-3386
Department of Statistics and Fax: 319-335-3017
Actuarial Science
241 Schaeffer Hall email: luke@stat.uiowa.edu
Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._