Implementation of JS reload without crashing

Summary:
On JS reload the FabricUIManager and EventDispatcher didn't get release due to a retain cycle. This breaks the cycle.

In addition, force release the Scheduler on reload so that the stale classes get cleaned up properly, avoiding crashes. Also the surface now remounts the content correctly

Reviewed By: shergin

Differential Revision: D8414916

fbshipit-source-id: 4b14031f29b3bc9987d7aa765dc0d930a7de2b1e
This commit is contained in:
Kevin Gozali
2018-06-15 10:56:40 -07:00
committed by Facebook Github Bot
parent 2ca4770011
commit cb19621dfe
5 changed files with 73 additions and 3 deletions

View File

@@ -35,6 +35,7 @@ Scheduler::Scheduler() {
Scheduler::~Scheduler() {
uiManager_->setDelegate(nullptr);
eventDispatcher_->setUIManager(nullptr);
}
void Scheduler::registerRootTag(Tag rootTag) {

View File

@@ -22,7 +22,7 @@ static std::string normalizeEventType(const std::string &type) {
return prefixedType;
}
void SchedulerEventDispatcher::setUIManager(std::shared_ptr<const FabricUIManager> uiManager) {
void SchedulerEventDispatcher::setUIManager(std::shared_ptr<const FabricUIManager> uiManager) const {
uiManager_ = uiManager;
}

View File

@@ -27,7 +27,7 @@ class SchedulerEventDispatcher final:
public:
void setUIManager(std::shared_ptr<const FabricUIManager> uiManager);
void setUIManager(std::shared_ptr<const FabricUIManager> uiManager) const;
#pragma mark - EventDispatcher
@@ -42,7 +42,8 @@ public:
private:
std::shared_ptr<const FabricUIManager> uiManager_;
// TODO: consider using std::weak_ptr<> instead for better memory management.
mutable std::shared_ptr<const FabricUIManager> uiManager_;
};
} // namespace react