Fixed memory consumption of caches (#7064)

Thanks to @aleos89
This commit is contained in:
Lemongrass3110 2022-08-18 00:06:47 +02:00 committed by GitHub
parent 846dfd9bb4
commit df9ef6fa79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}
}
}
};