mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
RuntimeTarget refactor - ensure safe destruction of Instance Agents and Targets
Summary: Changelog: [Internal] In D53233914 we copied PageTarget's approach for keeping track of its sessions into InstanceTarget (for keeping track of InstanceAgents). Here we complete that pattern by asserting that the agents are destroyed before their respective targets. NOTE: We might want to encapsulate this pattern in a helper/template class at some point. For now I'm going with the explicit approach. Reviewed By: hoxyq Differential Revision: D53266708 fbshipit-source-id: 4a90fde6c68e87d4667c44f81f8578a7a9072474
This commit is contained in:
committed by
Facebook GitHub Bot
parent
415bb718ff
commit
19012ca9ee
@@ -30,6 +30,21 @@ std::shared_ptr<InstanceAgent> InstanceTarget::createAgent(
|
||||
return instanceAgent;
|
||||
}
|
||||
|
||||
void InstanceTarget::removeExpiredAgents() {
|
||||
// Remove all expired agents.
|
||||
forEachAgent([](auto&) {});
|
||||
}
|
||||
|
||||
InstanceTarget::~InstanceTarget() {
|
||||
removeExpiredAgents();
|
||||
|
||||
// Agents are owned by the session, not by InstanceTarget, but
|
||||
// they hold an InstanceTarget& that we must guarantee is valid.
|
||||
assert(
|
||||
agents_.empty() &&
|
||||
"InstanceAgent objects must be destroyed before their InstanceTarget. Did you call PageTarget::unregisterInstance()?");
|
||||
}
|
||||
|
||||
RuntimeTarget& InstanceTarget::registerRuntime(
|
||||
RuntimeTargetDelegate& delegate) {
|
||||
assert(!currentRuntime_ && "Only one Runtime allowed");
|
||||
|
||||
@@ -53,6 +53,7 @@ class InstanceTarget {
|
||||
InstanceTarget(InstanceTarget&&) = delete;
|
||||
InstanceTarget& operator=(const InstanceTarget&) = delete;
|
||||
InstanceTarget& operator=(InstanceTarget&&) = delete;
|
||||
~InstanceTarget();
|
||||
|
||||
std::shared_ptr<InstanceAgent> createAgent(
|
||||
FrontendChannel channel,
|
||||
|
||||
Reference in New Issue
Block a user