Immediately destroy C++ state when deleteView is processed

Summary:
Followup to D26858584 (https://github.com/facebook/react-native/commit/00959ffd6b9aebf52ca51ce7a747a375b5a8cdd1). We should also immediately destroy C++ state memory (which will decrement a shared_ptr) when deleting a view.

This could improve memory while a surface is being used.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D26876537

fbshipit-source-id: fc8353bed47db8fdbf5c7f6c6253ac788c460d9a
This commit is contained in:
Joshua Gross
2021-03-07 13:19:50 -08:00
committed by Facebook GitHub Bot
parent 077e434d77
commit b84ae3875c
@@ -778,6 +778,12 @@ public class SurfaceMountingManager {
// or StopSurface being called, so we do not handle deleting descendents of the View.
mTagToViewState.remove(reactTag);
// Destroy state immediately instead of waiting for Java GC.
if (viewState.mStateWrapper != null) {
viewState.mStateWrapper.destroyState();
viewState.mStateWrapper = null;
}
// For non-root views we notify viewmanager with {@link ViewManager#onDropInstance}
ViewManager viewManager = viewState.mViewManager;
if (!viewState.mIsRoot && viewManager != null) {