In the React Native documentation for integrating with Android, it includes this snippet for integrating with Android:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModulePath("index")
.addPackage(new MainReactPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "MyReactNativeApp", null);
setContentView(mReactRootView);
}
However, when I use this as-is I get a 100% repro memory leak caused by a ThemedReactContext holding a reference to the ReactRootView which holds a reference to my custom activity.
This is because the Context argument passed to the constructor of ReactRootView is this, which is a reference to my custom activity.
Instead, if I do:
mReactRootView = new ReactRootView(getApplication());
I get no memory leaks.
Is it safe to change the source of my context for a new ReactRootView, and is this a bug that should either a) be fixed or b) should see the documentation changed?