Skip to content

iOS Event Memory Leak #26308

Closed
Closed
@robzyb

Description

@robzyb

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPlatform: iOSiOS applications.Ran CommandsOne of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions