mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Don't retain State in StateWrapperImpl
Summary:
Changelog: [internal]
StateWrapperImpl shouldn't retain State strongly because cleanup of `StateWrapperImpl` is triggered from Java and isn't guaranteed to take happen before runtime is destroyed.
This should resolve crash where `StateWrapperImpl`'s destruction causes a `~Pointer` to be called after runtime is destroyed.
Chain of ownership that will be broken by storing State weakly inside `StateWrapperImpl`.
`StateWrapperImpl -> ParagraphState -> TextLayourManager's cache -> AttributedString -> ShadowView -> EventEmitter -> EventTarget -> Pointer`
{F451105831}
Reviewed By: JoshuaGross
Differential Revision: D26815275
fbshipit-source-id: 0703c6dccc62c1d152923b786a83273fa8a03694
This commit is contained in:
committed by
Facebook GitHub Bot
parent
75d9ba733f
commit
e6931caca4
@@ -23,17 +23,24 @@ jni::local_ref<StateWrapperImpl::jhybriddata> StateWrapperImpl::initHybrid(
|
||||
}
|
||||
|
||||
jni::local_ref<ReadableNativeMap::jhybridobject> StateWrapperImpl::getState() {
|
||||
folly::dynamic map = state_->getDynamic();
|
||||
auto state = state_.lock();
|
||||
if (!state) {
|
||||
return nullptr;
|
||||
}
|
||||
folly::dynamic map = state->getDynamic();
|
||||
local_ref<ReadableNativeMap::jhybridobject> readableNativeMap =
|
||||
ReadableNativeMap::newObjectCxxArgs(map);
|
||||
return readableNativeMap;
|
||||
}
|
||||
|
||||
void StateWrapperImpl::updateStateImpl(NativeMap *map) {
|
||||
// Get folly::dynamic from map
|
||||
auto dynamicMap = map->consume();
|
||||
// Set state
|
||||
state_->updateState(dynamicMap);
|
||||
auto state = state_.lock();
|
||||
if (state) {
|
||||
// Get folly::dynamic from map
|
||||
auto dynamicMap = map->consume();
|
||||
// Set state
|
||||
state->updateState(dynamicMap);
|
||||
}
|
||||
}
|
||||
|
||||
void StateWrapperImpl::registerNatives() {
|
||||
|
||||
@@ -32,7 +32,7 @@ class StateWrapperImpl : public jni::HybridClass<StateWrapperImpl> {
|
||||
jni::alias_ref<jobject> self,
|
||||
int callbackRefId);
|
||||
|
||||
State::Shared state_;
|
||||
State::Weak state_;
|
||||
|
||||
private:
|
||||
jni::alias_ref<StateWrapperImpl::jhybriddata> jhybridobject_;
|
||||
|
||||
Reference in New Issue
Block a user