Selaa lähdekoodia

Fixed memory consumption of caches (#7064)

Thanks to @aleos89
Lemongrass3110 2 vuotta sitten
vanhempi
commit
df9ef6fa79
1 muutettua tiedostoa jossa 10 lisäystä ja 2 poistoa
  1. 10 2
      src/common/database.hpp

+ 10 - 2
src/common/database.hpp

@@ -196,8 +196,16 @@ public:
 			this->cache[key] = pair.second;
 		}
 
-		// Free the memory that was allocated too much
-		this->cache.shrink_to_fit();
+		for( auto it = this->cache.rbegin(); it != this->cache.rend(); it++ ){
+			if( *it != nullptr ){
+				// Resize to only fit all existing non null entries
+				this->cache.resize( this->cache.rend() - it );
+
+				// Free the memory that was allocated too much
+				this->cache.shrink_to_fit();
+				break;
+			}
+		}
 	}
 };