Skip to content
Snippets Groups Projects
Commit 2ce1ca48 authored by mattijs's avatar mattijs Committed by Andrew Heather
Browse files

BUG: objectRegistry: two-pass deletion. See #1276.

parent 5dd6a04f
No related merge requests found
......@@ -334,6 +334,14 @@ bool Foam::objectRegistry::checkOut(const word& key) const
void Foam::objectRegistry::clear()
{
// Free anything owned by the registry
// This needs to be done in two stages:
// - collect objects-to-be-removed
// - actually delete objects
// since the destructor of the regIOobject will actually delete its
// entry from the objectRegistry which messes up the iterator.
DynamicList<regIOobject*> owned;
for (iterator iter = begin(); iter != end(); ++iter)
{
regIOobject* ptr = iter.val();
......@@ -341,17 +349,25 @@ 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;
owned.append(ptr);
}
}
for (regIOobject* objectPtr : owned)
{
// Make sure that the destructor of the regIOobject does a checkout
objectPtr->release();
delete objectPtr;
}
HashTable<regIOobject*>::clear();
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment