Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large R6 inside a list memory leak #3544

Closed
ksavin opened this issue Sep 26, 2018 · 2 comments

Comments

@ksavin
Copy link

commented Sep 26, 2018

Hello

There's a consistently reproducible memory leak when creating R6 object with a large vector and placing it in a list. Reproduces only from Rstudio IDE. Not happening in R GUI.

After executing the code below, IDE becomes unresponsive and gradually eats all memory resources available.

Steps to reproduce:

library(R6)

TestR6 <- R6Class(
  "test",
  public = list(
    initialize = function(n) {
      self$m <- rnorm(n)
    },
    m = NULL
  )
)
test <- TestR6$new(1e8)
lst <- list(test)

Tested on various versions:

Windows RStudio desktop Version 1.1.453

R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] R6_2.2.2

loaded via a namespace (and not attached):
[1] compiler_3.5.1 tools_3.5.1    yaml_2.2.0 

Windows RStudio Version 1.2.907

R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
 
Matrix products: default
 
locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    
 
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
 
other attached packages:
[1] R6_2.2.2
 
loaded via a namespace (and not attached):
[1] compiler_3.5.1 tools_3.5.1   

Linux RStudio Desktop Version 1.1.442

R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 17.10
 
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so
 
locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8       
 [4] LC_COLLATE=en_GB.UTF-8     LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       
 
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
 
other attached packages:
[1] R6_2.2.2
 
loaded via a namespace (and not attached):
[1] compiler_3.4.4 tools_3.4.4    yaml_2.1.18   

Also R Studio Server 1.1.419

Can't attach diagnostic report since IDE is unresponsive

@kevinushey

This comment has been minimized.

Copy link
Contributor

commented Sep 26, 2018

I suspect this is because RStudio is calling str() behind the scenes, which is very slow for your generated object. For example:

library(R6)
Big <- R6Class("Big", public = list(data = rnorm(1E7)))
big <- Big$new()
system.time(str(big))
#> Classes 'Big', 'R6' <Big>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     data: -0.594100136328869 0.104513371816434 0.531537555504934 - ...
#>    user  system elapsed 
#>  19.191   0.417  19.630

Note that the slowness here occurs regardless of whether you place your R6 object within a list.

@kevinushey

This comment has been minimized.

Copy link
Contributor

commented Sep 27, 2018

This should be fixed in the development version of R6 courtesy of @wch -- you can try installing it with

devtools::install_github("wch/R6")

Thanks for reporting!

@kevinushey kevinushey closed this Sep 27, 2018

@dfalty dfalty added the verified label Nov 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.