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
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?
Source: React natvie