Memory leakage with Shiny

Hi,
I am facing a memory leakage using Shiny.
I tested the code at Memory leak when using ggplot2, grobs, and tabs. Shiny or my bug?. I observed that the memory is increasing each time a new tab is added. Why is it different from the proposed solution?
Best.

Here is the output I get. I created 21 tabs, then played with the last one. At each tab created, the memory increased. When changing the parameters and refreshing the plot, the memory is stable, which sounds OK.

Listening on http://127.0.0.1:5029
  output: 9,829,752 B, mem used: 260 MB
  output: 9,564,080 B, mem used: 260 MB
  output: 13,836,296 B, mem used: 264 MB
  output: 18,113,328 B, mem used: 269 MB
  output: 22,389,544 B, mem used: 274 MB
  output: 26,662,808 B, mem used: 278 MB
  output: 30,932,080 B, mem used: 283 MB
  output: 35,218,776 B, mem used: 288 MB
  output: 39,507,840 B, mem used: 292 MB
  output: 43,776,504 B, mem used: 297 MB
  output: 48,060,248 B, mem used: 302 MB
  output: 52,340,328 B, mem used: 306 MB
  output: 56,617,560 B, mem used: 311 MB
  output: 60,889,400 B, mem used: 316 MB
  output: 65,172,600 B, mem used: 320 MB
  output: 69,444,576 B, mem used: 325 MB
  output: 73,719,408 B, mem used: 330 MB
  output: 77,995,144 B, mem used: 334 MB
  output: 82,266,176 B, mem used: 339 MB
  output: 86,541,544 B, mem used: 344 MB
  output: 90,819,704 B, mem used: 348 MB
  output: 91,017,320 B, mem used: 348 MB
  output: 90,882,712 B, mem used: 348 MB
  output: 91,051,568 B, mem used: 348 MB
  output: 90,884,376 B, mem used: 348 MB
  output: 91,051,008 B, mem used: 348 MB
  output: 90,883,768 B, mem used: 348 MB
  output: 91,053,992 B, mem used: 349 MB
  output: 90,714,912 B, mem used: 348 MB
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

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

other attached packages:
[1] gridExtra_2.3            pryr_0.1.5               ggplot2_3.3.6            shinyjs_2.1.0           
[5] shinyFiles_0.9.2         shinydashboard_0.7.2     shiny_1.7.1

You are objecting to memory increases corresponding to adding additional tabs of content ?
you are adding more things, it takes more memory to represent more things.
My sincere apologies if I'm missing something here, its been a long day for me.

Thanks for your feedback. What you said makes sense, and I agree.
What I don't understand is why Barret's solution does not return a similar result as mine.
Best.

I'm at a loss to understand what you are comparing "Barrett's solution" with? was it some other code posted in that same linked thread ? is it some private app of your own ?

I originally thought you were only discussing Barret's and the output you posted came from that ?
can you clarify ?

Because I am facing a memory leakage and I am thinking it sounds like the one mentioned, I tried Barret's code. The output came from the exact/intact code of Barret. I am wondering why my output is not the same as the one published. I cannot clarify more than that.

Hi @SamGG,

I think one possible reason why you don't get the same output as Barret is because you don't do exactly the same thing. Let me explain: The creation of new tab and plot is under control of user's click.
If I click on Add Tab and wait until plot appears before clicking once again on Add tab and so on 21 times, I get the same output as you got.

Which as pointed by @nirgrahamuk makes sense i.e.

memory increases corresponding to adding additional tabs of content

However, if I click many times super fast then the tabs are created but the plot is not see below corresponding to the DOM where base64 img has not been inserted in tab 7 and the output does not report large amount of memoy consumption (maybe this is what Barret did...)

But if I revisit the tab created wait for the plot to appear and then create a new tab, then, output updates showing an amount that seems to correspond to the memory used for plotting.

There was a very instructive talk (among many others ) during Appsilon Shiny Conference given by Jonas Hagenberg https://www.youtube.com/watch?v=W7ES6QYvN_c that you may be interested to watch.
Notably after 17:14, because Jonas Hagenberg describes that dynamically created inputs can negatively impact your app performance (maybe this is what is happening to you, it's hard to help you more about your own issue because you are using the example that comes from another ) and shows how to clean things on the server side.

HTH

1 Like

Thanks a lot for this documented answer.
Best,
Samuel

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.