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

iOS Event Memory Leak #26308

Closed
robzyb opened this issue Sep 3, 2019 · 3 comments
Closed

iOS Event Memory Leak #26308

robzyb opened this issue Sep 3, 2019 · 3 comments
Labels
Bug Platform: iOS iOS applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@robzyb
Copy link

robzyb commented Sep 3, 2019

I have some Swift code that sends events to React Native via RCTEventEmitter.

It is sending events with quite large NSArrays, and there is a memory leak. Both on the simulator and on a device memory increases to roughly 1.3GB after 30 seconds and the app crashes.

This totally could be an issue with my code, but I'm pretty sure that I've done things exactly per the documentation for sending-events-to-javascript.

React Native version:

System:
    OS: macOS 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz
    Memory: 871.71 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.9.1 - /usr/local/bin/node
    npm: 6.9.0 - /usr/local/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
  IDEs:
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60.5 => 0.60.5 
  npmGlobalPackages:
    react-native-cli: 2.0.1
    react-native-create-library: 3.1.2
    react-native-demo: 2.0.1
    react-native: 0.60.5

Steps To Reproduce

  1. Create project using react-native init
  2. Implement simple native module using RCTEventEmitter in Swift
  3. Run in iOS (sim or device) and observe memory leak and crash.

Describe what you expected to happen: No memory leak

Snack, code example, screenshot, or link to a repository:

The behaviour can be seen in the following repo. The first commit is a simple react-native init project, and the second commit is the code using RCTEventEmitter which creates the memory leak.

https://github.com/robzyb/rn-memory-leak

The memory leak can be replicated by simply `react-native run-ios'

Investigation so far

I have spent many hours on this but I haven't been able to nail it down. Javascript debug tools show a relatively constant 10/20MB usage, but Xcode shows the memory leak in action. Suggesting that the problem is with the Swift/Objective-C side.

@robzyb robzyb added the Bug label Sep 3, 2019
@react-native-bot react-native-bot added the Platform: iOS iOS applications. label Sep 3, 2019
@react-native-bot
Copy link
Collaborator

Thanks for submitting your issue. Can you take another look at your description and make sure the issue template has been filled in its entirety?

👉 Click here if you want to take another look at the Bug Report issue template.

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Resolution: Needs More Information labels Sep 3, 2019
@robzyb
Copy link
Author

robzyb commented Sep 4, 2019

I've done some further investigation, and it seems like the memory leak is coming from https://github.com/facebook/react-native/blob/master/React/CxxUtils/RCTFollyConvert.mm#L15

Unfortunately I don't yet know what pattern is being followed here. I'm a bit surprised that there's a Folly object being converted to an ObjectiveC object.

@robzyb
Copy link
Author

robzyb commented Sep 4, 2019

After all that, it turns out that changing the 'Build Configuration' in Xcode from Debug to Release stopped the memory leak.

Endless Googling about various possibilities lead me to this not-very-related Stackoverflow post where a commenter mentioned the Debug/Release difference:

https://stackoverflow.com/questions/34939508/react-nativehow-to-release-horrible-memory-usage-in-integrated-dev-environment

@robzyb robzyb closed this as completed Sep 4, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Oct 4, 2021
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: iOS iOS applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

2 participants