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

Fix invalidateLater memory leak #2555

Merged
merged 1 commit into from Aug 26, 2019
Merged

Conversation

wch
Copy link
Collaborator

@wch wch commented Aug 19, 2019

Closes #2267.

It looks like this particular leak was introduced by #2022.

In this test app, it redraws the plot and checks the memory used once per second.

Before this PR, the memory increases by about 7kB each iteration; after this PR, it does not increase at all (after the first few iterations).

library(shiny)
library(pryr)

ui <- fluidPage(
  plotOutput("hist1"),
  verbatimTextOutput("Memory")
)

server <- function(input, output, session) {
  i <- 0
  last_mem <- mem_used()

  output$hist1 <- renderPlot({
    invalidateLater(1000)
    plot(c(1:100))
  })
    
  output$Memory <- renderText({
    invalidateLater(1000)
    cur_mem <- mem_used()
    on.exit({
      i <<- i + 1
      last_mem <<- cur_mem
    })
    paste0(
      "Iteration:    ", i, "\n",
      "Memory usage: ", cur_mem, "\n",
      "Increase:     ", cur_mem - last_mem
    )
  })
}

shinyApp(ui,server)

Screenshot of before:

2019-08-19 12 31 21

And after:
2019-08-19 12 31 45

@wch wch requested a review from jcheng5 August 19, 2019 17:32
@wch wch added this to the 1.5 milestone Aug 20, 2019
@ramindehghanpoor
Copy link

@wch Sorry, I'm not a professional. I'm trying your test app, and still, the memory usage is increasing. I reinstalled the development version of shiny from Github. Should I reinstall anything else to fix the problem?

@wch
Copy link
Collaborator Author

wch commented Aug 20, 2019

@ramindehghanpoor You need to install the branch in this pull request:

devtools::install_github("rstudio/shiny#2555")

@ramindehghanpoor
Copy link

@wch Thank you. It worked on my computer. Can I install the branch in this pull request and use this good version for our company website as well? We are using DigitalOcean server.

@wch
Copy link
Collaborator Author

wch commented Aug 20, 2019

You could, but this is a development branch of shiny and has not been tested as extensively as the current CRAN version of shiny, so it's possible you'll encounter bugs with it.

@jcheng5 jcheng5 modified the milestones: 1.5, 1.4 Aug 26, 2019
@jcheng5 jcheng5 merged commit cc2173c into master Aug 26, 2019
@jcheng5 jcheng5 deleted the wch-fix-invalidatelater-leak branch August 26, 2019 17:51
@yishan-guo
Copy link

@wch Sorry when I tryed devtools::install_github("#2555"), I got the error

devtools::install_github("#2555")
Error: Failed to install 'unknown package' from GitHub:
HTTP error 404.
No commit found for the ref wch-fix-invalidatelater-leak

Did you spell the repo owner (rstudio) and repo name (shiny) correctly?

  • If spelling is correct, check that you have the required permissions to access the repo.

any idea why?

@wch
Copy link
Collaborator Author

wch commented Aug 30, 2019

This branch has been merged into master, so all you need to do now is this:

devtools::install_github("rstudio/shiny")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possibly Memory Leak?
4 participants