From 88e891cfb18d9bacf203e465bf81e464aed404d9 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Wed, 10 Apr 2019 11:30:31 +0200 Subject: [PATCH] ENH: force clearing of Time objectRegistry on destruction (#1276) - the objectRegistry destructor seems to be called too late. Explicitly clear the objectRegistry within the Time destructor to ensure that it always happens. --- src/OpenFOAM/db/Time/Time.C | 5 ++++- src/OpenFOAM/db/objectRegistry/objectRegistry.C | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index 254d9a6735f..25ee99ba46e 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2011, 2015-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011, 2015-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2017 OpenFOAM Foundation @@ -727,6 +727,9 @@ Foam::Time::~Time() // Clean up profiling profiling::stop(*this); + + // Ensure all owned objects are also cleaned up now + objectRegistry::clear(); } diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index 3e1fbebc055..0c9535f35a0 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -323,6 +323,14 @@ void Foam::objectRegistry::clear() if (ptr && ptr->ownedByRegistry()) { + // TBD: may wish to have ptr->clearWatches(); + + if (objectRegistry::debug) + { + Pout<< "objectRegistry::clear : " << ptr->name() + << " watches :" << flatOutput(ptr->watchIndices()) << nl; + + } delete ptr; } } @@ -350,6 +358,7 @@ bool Foam::objectRegistry::erase(const iterator& iter) if (ptr && ptr->ownedByRegistry()) { + // TBD: may wish to have ptr->clearWatches(); delete ptr; } -- GitLab