From 3ca4e0b4f9dc05f382d38bd191b0ab32be7ac4ab Mon Sep 17 00:00:00 2001 From: John Sully Date: Mon, 14 Jun 2021 04:06:34 +0000 Subject: [PATCH] Free objects immediately before adding to the GC list, this cuts down on mem consumption Former-commit-id: 49d718ae9c1c8a850df5ffa2c550df3381ad7174 --- src/dict.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dict.cpp b/src/dict.cpp index 57872b5c4..d16fd77f7 100644 --- a/src/dict.cpp +++ b/src/dict.cpp @@ -535,7 +535,8 @@ dictAsyncRehashCtl::~dictAsyncRehashCtl() { while (deGCList != nullptr) { auto next = deGCList->next; dictFreeKey(dict, deGCList); - dictFreeVal(dict, deGCList); + if (deGCList->v.val != nullptr) + dictFreeVal(dict, deGCList); zfree(deGCList); deGCList = next; } @@ -694,6 +695,8 @@ static dictEntry *dictGenericDelete(dict *d, const void *key, int nofree) { d->ht[table].table[idx] = he->next; if (!nofree) { if (table == 0 && d->asyncdata != nullptr && (ssize_t)idx < d->rehashidx) { + dictFreeVal(d, he); + he->v.val = nullptr; he->next = d->asyncdata->deGCList; d->asyncdata->deGCList = he; } else { @@ -752,6 +755,8 @@ void dictFreeUnlinkedEntry(dict *d, dictEntry *he) { if (he == NULL) return; if (d->asyncdata) { + dictFreeVal(d, he); + he->v.val = nullptr; he->next = d->asyncdata->deGCList; d->asyncdata->deGCList = he; } else { @@ -775,6 +780,8 @@ int _dictClear(dict *d, dictht *ht, void(callback)(void *)) { while(he) { nextHe = he->next; if (d->asyncdata && (ssize_t)i < d->rehashidx) { + dictFreeVal(d, he); + he->v.val = nullptr; he->next = d->asyncdata->deGCList; d->asyncdata->deGCList = he; } else {