From 0eb7c7bc434a6c14e67ce7a57453c56a7ac3fbba Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Fri, 8 Nov 2019 22:17:32 -0800 Subject: [PATCH] Fabric: Resetting *all* ShadowNode pointers in `MountingCoordinator::revoke` Summary: With this diff (and maybe other coming in the future), we are enforcing a model where Fabric Core actively/architecturally prevents `jsi::Object` to overlive `UIManager`. That never was a promise that but I think it's achievable; it should help to eliminate the whole class of possible crashes (application layer still must ensure that Scheduler is deallocated before `jsi::Runtime`). Clearing all pointers to `ShadowNode`s in `MountingCoordinator` prevents from extending the lifetime of ShadowNodes stored inside revoked `MountingCoordinator` (the lifetime of `MountingCoordinator` is up to application layer). That should help prevent crashes (not all of them!) caused by `jsi::Object`s overliving `jsi::Runtime`. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D18333708 fbshipit-source-id: 4391998b8f805563cfaff834fc56e85b98bc4d68 --- ReactCommon/fabric/mounting/MountingCoordinator.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ReactCommon/fabric/mounting/MountingCoordinator.cpp b/ReactCommon/fabric/mounting/MountingCoordinator.cpp index a063a2e6f1a..93b7fb24ebe 100644 --- a/ReactCommon/fabric/mounting/MountingCoordinator.cpp +++ b/ReactCommon/fabric/mounting/MountingCoordinator.cpp @@ -52,6 +52,11 @@ void MountingCoordinator::push(ShadowTreeRevision &&revision) const { void MountingCoordinator::revoke() const { std::lock_guard lock(mutex_); + // We have two goals here. + // 1. We need to stop retaining `ShadowNode`s to not prolong their lifetime + // to prevent them from overliving `ComponentDescriptor`s. + // 2. A possible call to `pullTransaction()` should return empty optional. + baseRevision_.rootShadowNode_.reset(); lastRevision_.reset(); }