From 4a43cb1c6e5ba304d70df7066c61c52718a5f249 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 5 Oct 2005 21:45:27 +0000 Subject: Fixed some resource cleanup and memory leaks. Also changed the way dangling references to resources are reported to be more informative. --- src/resources/resource.h | 6 ++++++ src/resources/resourcemanager.cpp | 15 ++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src/resources') diff --git a/src/resources/resource.h b/src/resources/resource.h index ce3a62fb..fe534606 100644 --- a/src/resources/resource.h +++ b/src/resources/resource.h @@ -53,6 +53,12 @@ class Resource bool decRef(); + /** + * Return the path identifying this resource. + */ + const std::string& + getIdPath() { return mIdPath; } + protected: /** * Destructor. diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index c941e16e..4a8a010a 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -31,6 +31,7 @@ #include "soundeffect.h" #include "../log.h" +#include "../gui/button.h" ResourceManager *ResourceManager::instance = NULL; @@ -43,23 +44,23 @@ ResourceManager::~ResourceManager() { // Create our resource iterator. std::map::iterator iter = resources.begin(); - int danglingResources = 0; - int danglingReferences = 0; // Iterate through and release references until objects are deleted. while (!resources.empty()) { Resource *res = resources.begin()->second; - danglingResources++; + std::string id = res->getIdPath(); + + int references = 0; do { - danglingReferences++; + references++; } while (!res->decRef()); - } - logger->log("ResourceManager::~ResourceManager() cleaned up %d references " - "to %d resources", danglingReferences, danglingResources); + logger->log("ResourceManager::~ResourceManager() cleaned up %d " + "references to %s", references, id.c_str()); + } } bool -- cgit v1.2.3-70-g09d2