aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/memorypool.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/common/memorypool.cpp b/common/memorypool.cpp
index 68da830cf2..d5dcbcc8c8 100644
--- a/common/memorypool.cpp
+++ b/common/memorypool.cpp
@@ -149,14 +149,16 @@ void MemoryPool::freeUnusedPages() {
// printf("freed %d pages out of %d\n", (int)freedPagesCount, (int)_pages.size());
- for (size_t i = 0; i < _pages.size(); ) {
- if (_pages[i].start == NULL) {
- _pages.remove_at(i);
- // We just removed an entry, so we do not advance "i"
- } else {
- ++i;
+ // Remove all now unused pages
+ size_t newSize = 0;
+ for (size_t i = 0; i < _pages.size(); ++i) {
+ if (_pages[i].start != NULL) {
+ if (newSize != i)
+ _pages[newSize] = _pages[i];
+ ++newSize;
}
}
+ _pages.resize(newSize);
// Reset _chunksPerPage
_chunksPerPage = INITIAL_CHUNKS_PER_PAGE;