Perform cleanup when ReactApplicationContext is destroyed

Summary:
## Description
When we reload the app, `ReactApplicationContext.destroy()` is called. This method calls `CatalystInstanceImpl.destroy()`, which (on the NativeModules thread) calls `NativeModuleRegistry.notifyJSInstanceDestroy()`, which loops over all its `ModuleHolder`s, and calls `ModuleHolder.destroy()`, each of which call their NativeModule's `onCatalystInstanceDestroy()` method.

TurboModuleManager is a `JSIModule`, so it also has its `onCatalystInstanceDestroy()` method called when the `ReactApplicationContext` is destroyed. But `TurboModuleManager.onCatalystInstanceDestroy()` doesn't do anything. Instead, at the very least, it should call `onCatalystInstanceDestroy()` of all NativeModules.

Reviewed By: mdvacca

Differential Revision: D16552730

fbshipit-source-id: 04459185262e92d69570facb368578a848cc5fdb
This commit is contained in:
Ramanpreet Nara
2019-08-01 16:31:48 -07:00
committed by Facebook Github Bot
parent e876cc68e7
commit e6c8ace576
@@ -91,5 +91,15 @@ public class TurboModuleManager implements JSIModule, TurboModuleRegistry {
public void initialize() {}
@Override
public void onCatalystInstanceDestroy() {}
public void onCatalystInstanceDestroy() {
for (TurboModule turboModule : mTurboModules.values()) {
// TODO(T48014458): Rename this to invalidate()
((NativeModule) turboModule).onCatalystInstanceDestroy();
}
mTurboModules.clear();
// Delete the native part of this hybrid class.
mHybridData.resetNative();
}
}