diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-06-30 21:15:34 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-06-30 21:27:57 +0300 |
commit | fce58131916103f3c2120adafcf59895a402a634 (patch) | |
tree | aa2cebb167d7c6ffb90a71a631132779597bf2d4 /src/resources/resourcemanager.cpp | |
parent | 3e22726df1aecf9db96b558c9e7597166d685ad2 (diff) | |
download | mv-fce58131916103f3c2120adafcf59895a402a634.tar.gz mv-fce58131916103f3c2120adafcf59895a402a634.tar.bz2 mv-fce58131916103f3c2120adafcf59895a402a634.tar.xz mv-fce58131916103f3c2120adafcf59895a402a634.zip |
Extend leak detection features.
Diffstat (limited to 'src/resources/resourcemanager.cpp')
-rw-r--r-- | src/resources/resourcemanager.cpp | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 9b5394687..452bc9942 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -177,9 +177,12 @@ void ResourceManager::cleanUp(Resource *res) } delete res; +#ifdef DEBUG_LEAKS + cleanOrpahns(true); +#endif } -void ResourceManager::cleanOrphans(bool always) +bool ResourceManager::cleanOrphans(bool always) { timeval tv; gettimeofday(&tv, nullptr); @@ -187,8 +190,10 @@ void ResourceManager::cleanOrphans(bool always) time_t oldest = tv.tv_sec, threshold = oldest - 30; if (mOrphanedResources.empty() || (!always && mOldestOrphan >= threshold)) - return; + return false; + bool status(false); + status = false; ResourceIterator iter = mOrphanedResources.begin(); while (iter != mOrphanedResources.end()) { @@ -199,10 +204,11 @@ void ResourceManager::cleanOrphans(bool always) continue; } time_t t = res->mTimeStamp; - if (t >= threshold) + if (!always && t >= threshold) { - if (t < oldest) oldest = t; - ++iter; + if (t < oldest) + oldest = t; + ++ iter; } else { @@ -212,10 +218,12 @@ void ResourceManager::cleanOrphans(bool always) mOrphanedResources.erase(toErase); delete res; // delete only after removal from list, // to avoid issues in recursion + status = true; } } mOldestOrphan = oldest; + return status; } bool ResourceManager::setWriteDir(const std::string &path) @@ -602,6 +610,28 @@ ResourceManager *ResourceManager::getInstance() void ResourceManager::deleteInstance() { +#ifdef DUMP_LEAKED_RESOURCES + if (instance) + { + logger->log("clean orphans start"); + while(instance->cleanOrphans(true)); + logger->log("clean orphans end"); + ResourceIterator iter = instance->mResources.begin(); + + while (iter != instance->mResources.end()) + { + if (iter->second) + { + if (iter->second->getRefCount()) + { + logger->log("ResourceLeak: " + iter->second->getIdPath() + + " (" + toString(iter->second->getRefCount()) + ")"); + } + } + ++iter; + } + } +#endif delete instance; instance = nullptr; } |