You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having issues in my app where I navigate to a page, the RAM usage increases, then I navigate back, expecting the memory consumption to go back down, but the RAM usage stays high.
My app has two screens, screen A and screen B, both screens in a React Navigation Stack Navigator. We start on screen A.
Navigate to screen B. Screen B has a button that adds a giant string to a useState array. Do this however much you want, after 2 presses RAM usage goes up from ~100MB to about ~850MB on my device (iphone 12 mini).
Navigate back to screen A. I would expect memory to go back down, but it stays at that ~850MB level.
Additionally, here is a video of the test: https://www.youtube.com/shorts/ubiYwzrlaQw
Am I missing something? Is there any way to achieve the desired behavior of having RAM go down after navigating back?
I've asked chatGPT about this and it basically tells me that garbage collection in javascript is hard to predict and maybe somehow that memory will get freed later. However, I think that variations of this behavior are causing my app to steadily use more and more RAM as I navigate around, eventually causing it to crash.
Any help on understanding why this occurs and how to better handle memory when dealing with React Navigation would be greatly appreciated!
Note: I notice similar behavior without any navigation involved: allocating a big state var, then setting it to null, RAM usage stays high. I don't completely understand this -- my guess is that I just have to wait for garbage collection to kick in and eventually bring RAM usage back down. However, in my app, that never seems to happen, it just keeps going up and eventually it crashes.
Expected behavior
I would expect RAM to go back down after navigating back to page A.
I have the same issue here. Our app starts with 200M and just navigate to screen A and goBack and navigate again one more time, it's got 900M RAM, that crazy with just 2 screens.
Current behavior
I'm having issues in my app where I navigate to a page, the RAM usage increases, then I navigate back, expecting the memory consumption to go back down, but the RAM usage stays high.
Here is a repo where I provide a reproducible example: https://github.com/spagrhetti/performance-debugging
The basic setup is this:
Additionally, here is a video of the test: https://www.youtube.com/shorts/ubiYwzrlaQw
Am I missing something? Is there any way to achieve the desired behavior of having RAM go down after navigating back?
I've asked chatGPT about this and it basically tells me that garbage collection in javascript is hard to predict and maybe somehow that memory will get freed later. However, I think that variations of this behavior are causing my app to steadily use more and more RAM as I navigate around, eventually causing it to crash.
Any help on understanding why this occurs and how to better handle memory when dealing with React Navigation would be greatly appreciated!
Note: I notice similar behavior without any navigation involved: allocating a big state var, then setting it to null, RAM usage stays high. I don't completely understand this -- my guess is that I just have to wait for garbage collection to kick in and eventually bring RAM usage back down. However, in my app, that never seems to happen, it just keeps going up and eventually it crashes.
Expected behavior
I would expect RAM to go back down after navigating back to page A.
Reproduction
https://github.com/spagrhetti/performance-debugging
Platform
Packages
Environment
The text was updated successfully, but these errors were encountered: