From 8bce9c59bba380ff0562db7e525e82a0c16cafef Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 15 Oct 2019 07:52:47 -0700 Subject: [PATCH] Fabric: Assert on destruction non-empty of ShadowTreeRegistry Summary: Destruction of Scheduler (and ShadowTreeRegistry as part of it) which has some running Surfaces is not a good thing and practically a bug on the application layer. With this assert we throw early to flag the issue. Changelog: [Internal] - Dev only assert indicating a broken invariant in ShadowTreeRegistry Reviewed By: sammy-SC Differential Revision: D17924491 fbshipit-source-id: 6b7433fe47630e993e7d5b969f3113f96124b6c9 --- ReactCommon/fabric/mounting/ShadowTreeRegistry.cpp | 4 ++++ ReactCommon/fabric/mounting/ShadowTreeRegistry.h | 1 + 2 files changed, 5 insertions(+) diff --git a/ReactCommon/fabric/mounting/ShadowTreeRegistry.cpp b/ReactCommon/fabric/mounting/ShadowTreeRegistry.cpp index ffddb3a7f03..7e650be76ad 100644 --- a/ReactCommon/fabric/mounting/ShadowTreeRegistry.cpp +++ b/ReactCommon/fabric/mounting/ShadowTreeRegistry.cpp @@ -8,6 +8,10 @@ namespace facebook { namespace react { +ShadowTreeRegistry::~ShadowTreeRegistry() { + assert(registry_.size() == 0 && "Deallocation of non-empty `ShadowTreeRegistry`."); +} + void ShadowTreeRegistry::add(std::unique_ptr &&shadowTree) const { std::unique_lock lock(mutex_); diff --git a/ReactCommon/fabric/mounting/ShadowTreeRegistry.h b/ReactCommon/fabric/mounting/ShadowTreeRegistry.h index 67c58a7d2c1..c2afbf99d59 100644 --- a/ReactCommon/fabric/mounting/ShadowTreeRegistry.h +++ b/ReactCommon/fabric/mounting/ShadowTreeRegistry.h @@ -19,6 +19,7 @@ namespace react { class ShadowTreeRegistry final { public: ShadowTreeRegistry() = default; + ~ShadowTreeRegistry(); /* * Adds a `ShadowTree` instance to the registry.