From b84ae3875c501af832e237bb54c5b5168c93b5d3 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Sun, 7 Mar 2021 13:17:20 -0800 Subject: [PATCH] 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 --- .../react/fabric/mounting/SurfaceMountingManager.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java index 78b7afc28c..21f1f9a2da 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java @@ -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) {