diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx index 003da59551b5..54378a319ece 100644 --- a/include/o3tl/lru_map.hxx +++ b/include/o3tl/lru_map.hxx @@ -69,6 +69,14 @@ public: lru_map(size_t nMaxSize) : mMaxSize(nMaxSize ? nMaxSize : std::min(mLruMap.max_size(), mLruList.max_size())) {} + ~lru_map() + { + // Some code .e.g. SalBitmap likes to remove itself from a cache during it's destructor, which means we + // get calls into lru_map while we are in destruction, so use the swap-and-clear idiom to avoid those problems. + mLruMap.clear(); + list_t aLruListTemp; + aLruListTemp.swap(mLruList); + } void insert(key_value_pair_t& rPair) {