diff --git a/src/ccutil/object_cache.h b/src/ccutil/object_cache.h index 8d442e4c..ad2c7b38 100644 --- a/src/ccutil/object_cache.h +++ b/src/ccutil/object_cache.h @@ -96,12 +96,16 @@ public: void DeleteUnusedObjects() { std::lock_guard guard(mu_); - for (auto it = cache_.rbegin(); it != cache_.rend(); ++it) { - if (it->count <= 0) { - delete it->object; - cache_.erase(std::next(it).base()); - } - } + cache_.erase(std::remove_if(cache_.begin(), cache_.end(), + [](const ReferenceCount &it) { + if (it.count <= 0) { + delete it.object; + return true; + } else { + return false; + } + }), + cache_.end()); } private: