From 663586b8d07c979218ceff79576bb549ee1973c5 Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Mon, 22 Jun 2026 21:58:54 -0300 Subject: Ephemeral relations --- src/LifecycleManager.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/LifecycleManager.cpp') diff --git a/src/LifecycleManager.cpp b/src/LifecycleManager.cpp index 4a12e09..10f3bb1 100644 --- a/src/LifecycleManager.cpp +++ b/src/LifecycleManager.cpp @@ -1,5 +1,6 @@ #include "LifecycleManager.h" +#include "EphemeralRelation.h" #include "Merkle.h" #include "Types.h" @@ -44,6 +45,20 @@ namespace nt { return object != nullptr; } + bool LifecycleManager::Collect(ObjectManager::registry* object) { + if (!IsEligibleForGC(object)) + return false; + // Named-lifetime types (BRANCH / SESSION) never auto-collect; TryCollect + // would no-op on them, so return false rather than report a collection. + if (object->head->type != nullptr) { + const auto label = object->head->type->label; + if (label == BRANCH || label == SESSION) + return false; + } + TryCollect(object); + return true; + } + void LifecycleManager::TryCollect(ObjectManager::registry* object) { if (!IsEligibleForGC(object)) return; @@ -66,6 +81,8 @@ namespace nt { CascadeMultigroup(object); if (label == BRANCH_TREE) CascadeBranchTree(object); + if (label == EPHEMERAL_RELATION) + CascadeEphemeral(object); objects_.Unregister(object->head->path); } @@ -140,4 +157,27 @@ namespace nt { for (auto* mg : mgs) Unpin(mg); } + + void LifecycleManager::CascadeEphemeral(ObjectManager::registry* ephemeral) { + if (ephemeral == nullptr || ephemeral->object == nullptr) + return; + auto* er = dynamic_cast(ephemeral->object.get()); + if (er == nullptr) + return; + + // Resolve each dependency path and collect before mutating: Unpin can + // cascade further GC, and iteration must outlive that mutation. + std::vector deps; + for (const auto& dep : er->dependencies) { + const auto parts = Ephemeral::SplitPath(dep); + if (parts.empty()) + continue; + auto* entry = objects_.Find(parts); + if (entry != nullptr) + deps.push_back(entry); + } + + for (auto* dep : deps) + Unpin(dep); + } } // namespace nt -- cgit v1.2.3