react-native: Image and ImageBackground memory leaks in iOS?

Environment

  React Native Environment Info:
    System:
      OS: macOS 10.14.1
      CPU: x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
      Memory: 658.77 MB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.11.0 - /usr/local/bin/node
      Yarn: 1.10.1 - /usr/local/bin/yarn
      npm: 6.4.1 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
    IDEs:
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      @types/react: 16.7.7 => 16.7.7 
      @types/react-native: 0.57.13 => 0.57.13 
      react: 16.7.0-alpha.2 => 16.7.0-alpha.2 
      react-native: 0.57.5 => 0.57.7 
    npmGlobalPackages:
      react-native-cli: 2.0.1

Description

I noticed high memory usage in my app that didn’t go away. After tracing for leaks it looks like this is due to images. It seems like iOS is storing all images in memory and is never offloading them. I looked through documentation of Image but didn’t find anything related to image caching nor how to offload them manually. Below is my profiler output for leaks

screenshot 2018-11-28 at 13 37 32

Each “spike” happens when new image is used / loaded. All these images are local and stored in Images.xcassets folder i.e. when I load them it looks something like

This happens with images loaded from Images.xcassets as well as ones required locally, i.e.

<Image source={{ uri: 'image_name' }} />

<Image source={require("../src/assets/myImage.png")} />

Note: This is not actually a lot of images loaded on one page, rather me navigating through my app and loading new assets on different views, so images are mounted and unmounted, but memory seems to be accumulating.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 16
  • Comments: 21 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Still an issue

Still an issue: updated snack for expo 35

Testing on physical iPhone Xs on iOS 13.1.3, using the cached images crashes and reboots my phone, while using the remote images works smoothly.