diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-02-28 12:27:01 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-03-01 20:58:15 +0100 |
commit | 9c5f35ab258055fe70a94999a685ddb67184484b (patch) | |
tree | 3904b534d6a513aae404a793e2efb179c722bedf /src | |
parent | ff7411bb3d3ff2c74210c8f7c5d71a1315d08cad (diff) | |
download | mana-9c5f35ab258055fe70a94999a685ddb67184484b.tar.gz mana-9c5f35ab258055fe70a94999a685ddb67184484b.tar.bz2 mana-9c5f35ab258055fe70a94999a685ddb67184484b.tar.xz mana-9c5f35ab258055fe70a94999a685ddb67184484b.zip |
Fixed leaking of resources referenced by resources
While cleaning up resources on shutdown, the resources they in turn
referenced (like an Image referenced by an ImageSet) ended up in
mOrphanedResources. Since the orphaned resources were only taken into
account once, a lot of remaining orphans never got deleted.
Technically a non-issue because it leaked on shutdown only, but it
resulted in many faulty log entries about resources still being
referenced as well as much noise from memory leak detectors.
Diffstat (limited to 'src')
-rw-r--r-- | src/resources/resourcemanager.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 5045d21b..e62407e3 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -50,11 +50,12 @@ ResourceManager::ResourceManager() ResourceManager::~ResourceManager() { - // Put the orphaned resources into the main list for cleanup - mResources.insert(mOrphanedResources.begin(), mOrphanedResources.end()); - auto cleanupResources = [&](auto match) { + // Include any orphaned resources into the main list for cleanup + mResources.insert(mOrphanedResources.begin(), mOrphanedResources.end()); + mOrphanedResources.clear(); + for (auto iter = mResources.begin(); iter != mResources.end(); ) { if (match(iter->second)) @@ -76,8 +77,9 @@ ResourceManager::~ResourceManager() cleanupResources([](Resource *res) { return dynamic_cast<ImageSet *>(res); }); // Release remaining resources - for (const auto &resource : mResources) - cleanUp(resource.second); + cleanupResources([](Resource *res) { return true; }); + + assert(mOrphanedResources.empty()); } void ResourceManager::cleanUp(Resource *res) @@ -98,7 +100,7 @@ void ResourceManager::cleanOrphans() { // Delete orphaned resources after 30 seconds. time_t oldest = time(nullptr); - time_t threshold = oldest - 30; + const time_t threshold = oldest - 30; if (mOrphanedResources.empty() || mOldestOrphan >= threshold) return; |