mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Destroy Fabric State objects earlier in Java
Summary: There are races between BackgroundExecutor and Fabric/View teardown, where, because of the way things are set up currently, a View will strongly retain a pointer into some native State object which can keep a host of other objects alive in C++, even after stopSurface, and even after RN itself starts tearing down. To alleviate this, we more aggressively clear State from Java, without waiting for Java GC: 1) on stopSurface, 2) whenever a State object is stale from Java's perspective. This should allow us to keep all common updateState semantics, while only introducing a new edge-case that stateWrapper can be destroyed during mounting if stopSurface happens at the same time. In those cases, checking for NPEs should be sufficient. The possible race condition only really happens with updateState, so it's easier to check for. There should practically be no cases where there's a race between `stopSurface` and `getState`, because `getState` is only really called around state updates and view preallocation, and never after; we still check for NPEs in those cases, but it shouldn't be an issue. Changelog: [Internal] Reviewed By: thurn, sammy-SC, mdvacca Differential Revision: D26858584 fbshipit-source-id: 2ef7467220865380037d69d8de322fe8797f6a12
This commit is contained in:
1 parent
47779de424
commit
00959ffd6b
9 files changed
+85
-16
No files matched your search
@@ -9,6 +9,7 @@ package com.facebook.react.uimanager;
|
||||
|
||||
import com.facebook.react.bridge.ReadableNativeMap;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* This is a wrapper that can be used for passing State objects from Fabric C++ core to
|
||||
@@ -19,11 +20,20 @@ public interface StateWrapper {
|
||||
/**
|
||||
* Get a ReadableNativeMap object from the C++ layer, which is a K/V map of string keys to values.
|
||||
*/
|
||||
ReadableNativeMap getState();
|
||||
@Nullable
|
||||
ReadableNativeMap getStateData();
|
||||
|
||||
/**
|
||||
* Pass a map of values back to the C++ layer. The operation is performed synchronously and cannot
|
||||
* fail.
|
||||
*/
|
||||
void updateState(WritableMap map);
|
||||
|
||||
/**
|
||||
* Mark state as unused and clean up in Java and in native. This should be called as early as
|
||||
* possible when you know a StateWrapper will no longer be used. If there's ANY chance of it being
|
||||
* used legitimately, don't destroy it! It is expected that all StateWrappers are destroyed
|
||||
* immediately upon stopSurface.
|
||||
*/
|
||||
void destroyState();
|
||||
}
|
||||
Reference in new issue
Block a user