Commit 5878b6ed authored by Mark Olesen's avatar Mark Olesen
Browse files

BUG: clearing objectRegistry can leak memory (#1180)

- now free anything owned by the registry when doing a clear.

- the myriad of other ways to remove items (and potentially leaking)
  have not yet been addressed:
  * set, erase, retain, filterKeys, filterValues, filterEntries
parent f33061cc
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -85,21 +85,7 @@ Foam::objectRegistry::objectRegistry(const IOobject& io, const label nObjects)
Foam::objectRegistry::~objectRegistry()
{
List<regIOobject*> myObjects(size());
label nObjects = 0;
for (iterator iter = begin(); iter != end(); ++iter)
{
if (iter.val()->ownedByRegistry())
{
myObjects[nObjects++] = iter.val();
}
}
for (label i=0; i < nObjects; ++i)
{
checkOut(*myObjects[i]);
}
objectRegistry::clear();
}
......@@ -265,6 +251,30 @@ bool Foam::objectRegistry::checkOut(regIOobject& io) const
}
void Foam::objectRegistry::clear()
{
// Free anything owned by the registry
for (iterator iter = begin(); iter != end(); ++iter)
{
regIOobject* ptr = iter.val();
if (ptr && ptr->ownedByRegistry())
{
delete ptr;
}
}
HashTable<regIOobject*>::clear();
}
void Foam::objectRegistry::clearStorage()
{
objectRegistry::clear();
HashTable<regIOobject*>::clearStorage();
}
void Foam::objectRegistry::rename(const word& newName)
{
regIOobject::rename(newName);
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -430,15 +430,22 @@ public:
// Edit
//- Rename
virtual void rename(const word& newName);
//- Add a regIOobject to registry
bool checkIn(regIOobject& io) const;
//- Remove a regIOobject from registry
bool checkOut(regIOobject& io) const;
//- Clear all entries from the registry
// Performs a checkOut() for all objects that are ownedByRegistry
void clear();
//- Clear all entries from the registry and the table itself.
void clearStorage();
//- Rename
virtual void rename(const word& newName);
// Reading
......
Markdown is supported
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