Description
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
- Create project using
react-native init
- Implement simple native module using RCTEventEmitter in Swift
- 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.