0

Background: I'm implementing a native iOS map component in Swift to be used in my React Native app. It lazy loads tiles onto the map as the user zooms / pans around, which causes the memory usage to gradually increase.

Problem: Occasionally, the memory usage gets too high and I need to clear the tile cache to bring it back down. In iOS, I understand that you can implement didReceiveMemoryWarning in the UIViewController to release some memory, but native iOS components for React Native don't have a UIViewController, only a UIView.

Tried: I've tried listening for memory warnings at the React Native level (suggested here), and then calling a native method exposed by RCT_EXTERN_METHOD to free up some memory. However, I'd rather the native component take care of itself in terms of cleaning up memory.

TL;DR: How do I handle memory warnings at the iOS level for a React Native "native iOS" component?

1
  • Would you provide more details on loads tiles onto the map, maybe with code, of which component owns/manages these tiles? Commented Mar 8, 2020 at 11:43

1 Answer 1

4
+100

However, I'd rather the native component take care of itself in terms of cleaning up memory.

If you hold and manage tiles in native subclass of UIViewController (eg. TileViewController), then the simplest way is to do cleanup like in the following

class TileViewController: UIViewController {

    // this called automatically on system memory warning
    override func didReceiveMemoryWarning() { 
        super.didReceiveMemoryWarning()

        // clean up cached tiles here
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.