react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Memory Leak in 0.16

Open sghiassy opened this issue 10 years ago • 48 comments

Looks like the base React-Native app has a memory leak

Running react-native init AwesomeProject and then running the app produces the following memory graph.

screen shot 2015-12-11 at 5 47 49 am

sghiassy avatar Dec 11 '15 13:12 sghiassy

Hey sghiassy, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

  • If this is a feature request or a bug that you would like to be fixed by the team, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • If you don't know how to do something or not sure whether some behavior is expected or a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • We welcome clear issues and PRs that are ready for in-depth discussion; thank you for your contributions!

facebook-github-bot avatar Dec 11 '15 13:12 facebook-github-bot

@sghiassy could you try running it in production mode and seeing if the memory leak still exists? react-native bundle --dev=false and uncomment the appropriate line in AppDelegate.m?

There are several performance concerns that are ignored in dev mode, in order to allow for a good developer experience.

skevy avatar Dec 11 '15 17:12 skevy

I compiled the JS bundle using command

react-native bundle  --verbose='true' --reset-cache  --entry-file='index.ios.js' --platform='ios'  --bundle-output='build/main.jsbundle' --dev='false' 

and referenced the bundle in the app delegate.

screen shot 2015-12-11 at 12 25 39 pm

Running the application again produces the same memory problem. It almost seems like the memory growth in production mode seems worse

screen shot 2015-12-11 at 12 26 26 pm

sghiassy avatar Dec 11 '15 20:12 sghiassy

The project is using 0.16 but I believe I've seen the same problem on 0.15 as well

sghiassy avatar Dec 11 '15 20:12 sghiassy

Also be sure to test an iOS release binary instead of debug.

ide avatar Dec 11 '15 20:12 ide

@sghiassy as you can see in the log at the bottom of the screen, you're not running in non dev mode. It still says performance optimizations are off.

skevy avatar Dec 11 '15 21:12 skevy

gastonmorixe avatar Dec 12 '15 01:12 gastonmorixe

Regarding the memory leak:

dev = true

  • release: leak
  • debug: leak

dev = false

  • release: no leak
  • debug: no leak

I noticed this on a 0.14 to 0.16 upgrade last week. This evening I took a closer look with a fresh 0.16 project to confirm. Any ideas higher up? I'll see if I can profile further.

aroth avatar Dec 12 '15 01:12 aroth

If I'm not mistaken, I don't think we really care too much (at least right now) about any potential leaks on dev...that's kind of expected, given the fact that absolutely no performance optimizations are put into dev mode (on purpose, to allow for easy debugging).

So if there's no leak in production mode, I think we're good here.

Feel free to let me know if you feel differently.

skevy avatar Dec 12 '15 01:12 skevy

For me on 0.16:

debug = leak; release = no leak;

jadsonlourenco avatar Dec 12 '15 02:12 jadsonlourenco

I forked master, fixed a couple of things (package version) an leaks are gone on dev too

gastonmorixe avatar Dec 12 '15 02:12 gastonmorixe

@imton -- What did you change? I'd like to take a look.

aroth avatar Dec 12 '15 02:12 aroth

@aroth use master, not .16

gastonmorixe avatar Dec 12 '15 02:12 gastonmorixe

0.17.0-rc is still leaking, although at a much slower rate than 0.16. it's certainly in a better spot. as @skevy states, this may not be so critical at the moment. I tested 0.12 and the chart was very similar. 0.16 was the outlier.

screen shot 2015-12-11 at 10 10 14 pm

aroth avatar Dec 12 '15 03:12 aroth

@all - I guess what I'm trying to get at is an actionable issue here.

Do you, as community members, consider it a blocking (or even major) issue for the dev version of your React Native apps (that run in the simulator and on computers that probably have 16GB of RAM) to be leaking memory? If so, and even if I may disagree, let's start investigating what may be causing the memory leak.

If this is not an issue at the moment, and we've determined that the example app is not leaking memory in production mode (and I think we have determined that here), let's close this issue.

skevy avatar Dec 12 '15 03:12 skevy

Well my app on .16 was getting to 3Gb of ram in 1 minute on simulator, so sure it is important to fix. On the other hand, I don't know If I am up to the challenge :s Maybe master is leaking too, I can confirm is way better, but can't at the moment say if in my case it was solved 100% or not.

gastonmorixe avatar Dec 12 '15 03:12 gastonmorixe

@imton I won't exclude the possibility that there was some kind of memory leak regression on .16 - perhaps theres something to be said for having some type of suite of acceptance tests for perf before release (though, that's a huge amount of work).

If the leak is small enough on master to not be a detriment to the development process, then I think that's satisfactory at the moment.

skevy avatar Dec 12 '15 03:12 skevy

The leak rate is way too high to justify leaving it as is. I would appreciate an appropriate fix.

rclai avatar Dec 12 '15 04:12 rclai

@rclai are you on 0.17-rc? as mentioned above, the leak rate is not that high.

ide avatar Dec 12 '15 06:12 ide

Looks like I forget to set the scheme to release. In doing so, I can confirm that the memory leak disappears.. yay!

I think the fact that it doesn't happen on release builds certainly takes the problem down from a red issue to yellow. But I also can't advocate simply living with a memory leak of this size.

sghiassy avatar Dec 12 '15 06:12 sghiassy