[S] Memory problems: solution

Matthew Wiener (mcw@ln.nimh.nih.gov)
Wed, 25 Feb 1998 09:09:12 -0500 (EST)


The following came from Steve Sain, and works like a charm. The growth in
memory demands from Splus completely stops.

Charles Berry and Don Sun suggested saving the large matrix to a file, and
calling a C program to calculate the gradient. The C program would read
the large matrix from a disk, and memory could be managed explicitly in C.
I never tried this, since modifying nlminb (as below) worked so well.

---------- Forwarded message ----------
Date: Tue, 24 Feb 1998 14:02:48 -0600
From: Steve Sain <ssain@post.cis.smu.edu>
To: Matthew Wiener <mcw@ln.nimh.nih.gov>
Subject: Re: [S] Memory problems (update)

Matt,

I'm not sure that this will do the trick, but one thing that I've done is
modified nlminb a bit. The problem that I found (or was told by some S-Plus
person at a conference) is that there are numerous while loops inside nlminb
and that these while statements are subject to the rather infamous problem with
S-Plus not doing a good job of garbage collecting (or removing) on exiting the
loops. What I've done is gone through the code and added "NULL" to the end of
every while loop. For example:

# Original code
while(temp$iv[1] < 3) temp <- nlminb.0(temp, p, liv, lv,
objective, bounds, scale)

# New code
while(temp$iv[1] < 3) {
temp <- nlminb.0(temp, p, liv, lv,
objective, bounds, scale)
NULL
}

This has the effect of returning the null value on exiting the loop instead of
everything else that the while loop normally returns. To be honest, I just made
wholesale changes like this to every while loop. I never went back to see which
ones were causing my problems. In any event, I don't really understand what is
going on with the loops and the memory problems. But I've found that I don't
have problems with nlminb any more.

Steve Sain

-- 
Stephan R. Sain                           
Department of Statistical Science
Southern Methodist University
Dallas, TX 75275-0332
(214) 768-2459
ssain@mail.smu.edu

----------------------------------------------------------------------- This message was distributed by s-news@wubios.wustl.edu. To unsubscribe send e-mail to s-news-request@wubios.wustl.edu with the BODY of the message: unsubscribe s-news