-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep HostTarget registered until ReactHostImpl/ReactInstanceManager i…
…s invalidated (#45146) Summary: Pull Request resolved: #45146 Changelog: [Internal] Currently, on Android, we destroy the Fusebox `HostTarget` when we receive the `onHostDestroy` event, which (counterintuitively) does not mean the ReactHost/InstanceManager ("Java Host") is being destroyed. This can lead to situations where the `HostTarget` is destroyed too soon (e.g. when a single Java Host is reused across multiple Activities). Now that we have the `invalidate()` method on the Java Host classes, we can tie `HostTarget`'s destruction to that instead. Since calling `invalidate()` is explicitly optional, we also need to account for the case where the caller just lets go of the Java Host reference and expects GC to handle cleanup. This includes: * Breaking the retain cycle between the Java Host and its C++ part. We achieve this using `WeakReference` to reference the Java Host. * Making the C++ part of the Host safe to destroy from any thread (and in particular the finalizer thread). We achieve this by scheduling `HostTarget`'s unregistration (in C++) on the executor supplied by the Java Host. Reviewed By: hoxyq Differential Revision: D58284590 fbshipit-source-id: 4ee4780354fb81137b891d5891d6138ac215cbff
- Loading branch information
1 parent
a7adfef
commit 4a8f0ee
Showing
7 changed files
with
151 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/react-native/ReactAndroid/src/main/jni/react/jni/JWeakRefUtils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <fbjni/fbjni.h> | ||
|
||
namespace facebook::react { | ||
|
||
/** | ||
* Helper for constructing a JWeakReference. \see JWeakReference.h in fbjni. | ||
*/ | ||
template <typename T> | ||
inline jni::local_ref<jni::JWeakReference<T>> makeJWeakReference( | ||
jni::alias_ref<T> ref) { | ||
return jni::JWeakReference<T>::newInstance(ref); | ||
} | ||
|
||
} // namespace facebook::react |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.