question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Image and ImageBackground memory leaks in iOS?

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:16
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
0xAsimetriqcommented, Aug 6, 2019

Still an issue

2reactions
raphaelrkcommented, Nov 7, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to offload react-native images from memory (iOS)?
Is there a way to offload these images somehow i.e. when <Image /> component unmount or manually? EDIT These are not network images,...
Read more >
IOS: Using A Pattern Image As A Background -Memory Leak
UIColor colorWithPatternImage is buggy, do not use it. My experience is that it tends to greatly cripple performance on the device but not...
Read more >
Memory leak by UIImage init(contentsOfFile:) - Apple Developer
I tried to load image from my app's sandbox path using UIImage(contentsOfFile: path) , but it causes memory leak issues by instances of...
Read more >
What Are iOS Memory Leaks and How to Detect Them?
iOS memory leaks are one of the biggest problems for developers ... The image above is a classic example of a tell-tale memory...
Read more >
25 iOS App Performance Tips & Tricks - RayWenderlich.com
In addition to helping you avoid memory leaks, ARC can also improve your ... In iOS, only image resources are stored in named...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found