[R] Memory leak in nleqslv()
Ismail SEZEN
sezenismail at gmail.com
Mon Jun 12 12:31:05 CEST 2017
> On 12 Jun 2017, at 00:16, Andrew Leach <aleach at ualberta.ca> wrote:
>
> Hello all,
>
> I am relatively new to R, but enjoying it very much. I am hoping that
> someone on this list can help me with an issue I am having.
>
> I am having issues with iterations over nleqslv, in that the solver
> does not appear to clean up memory used in previous iterations. I
> believe I've isolated the/my issue in a small sample of code:
>
> library(nleqslv)
>
> cons_ext_test <- function(x){
> rows_x <- length(x)/2
> x_1 <- x[1:rows_x]
> x_2 <- x[(rows_x+1):(rows_x*2)]
> eq1<- x_1-100
> eq2<-x_2*10-40
> return(c(eq1,eq2))
> }
>
> model_test <- function()
> {
> reserves<-(c(0:200)/200)^(2)*2000
> lambda <- numeric(NROW(reserves))+5
> res_ext <- pmin((reserves*.5),5)
> x_test <- c(res_ext,lambda)
> #print(x_test)
> for(test_iter in c(1:1000))
> nleqslv(x_test,cons_ext_test,jacobian=NULL)
> i<- sort( sapply(ls(),function(x){object.size(get(x))}))
> print(i[(NROW(i)-5):NROW(i)])
> }
>
> model_test()
>
> When I run this over 1000 iterations, memory use ramps up to over 2.4 GB
>
> While running it with 10 iterations uses far less memory, only 95MB:
>
> Running it once has my rsession with 62Mb of use, so growth in memory
> allocation scales with iterations.
>
> Even after 1000 iterations, with 2+ GB of memory used by the R
> session, no large-sized objects are listed, although mem_use() shows
> 2+ GB of memory used.
>
> test_iter lambda res_ext reserves x_test
> 48 1648 1648 1648 3256
>
> I've replicated this on OS-X and in Windows both on a desktop and a
> Surface Pro, however colleagues have run this on their machines and
> not found the same result. gc() does not rectify the issue, although
> re-starting R does.
>
> Any help would be much appreciated.
>
> AJL
>
Hello Andrew,
I could replicated same result. I think it’s time to send a bug report to author (Berend Hasselman <bhh at xs4all.nl>).
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.5
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices datasets utils methods base
other attached packages:
[1] nleqslv_3.3
loaded via a namespace (and not attached):
[1] compiler_3.4.0 tools_3.4.0
More information about the R-help
mailing list