Skip to content

Commit

Permalink
fix diskann memory leak in diskann (#2019)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

Fixes #1995 mentioned memory leak in diskann.

Issue link:#1988

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
  • Loading branch information
YReddice authored Oct 11, 2024
1 parent 8e97056 commit 3a094ec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
20 changes: 13 additions & 7 deletions src/storage/knn_index/knn_diskann/inner/diskann_utils.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public:
void Insert(const Neighbor &nbr) {
if (size_ == capacity_ && data_[size_ - 1] < nbr)
return;

auto it = std::lower_bound(data_.begin(), data_.begin() + size_, nbr);
// if (it != data_.start()+size_ && (*it).id == nbr.id) {
// return;
Expand Down Expand Up @@ -315,7 +315,7 @@ public:
return ret;
}

bool Empty() { return (this->size() == 0); }
bool Empty() { return (this->Size() == 0); }

// PUSH BACK
void Push(T &new_val) {
Expand Down Expand Up @@ -380,17 +380,23 @@ public:
T *ScratchSpace() { return scratch_; }

~ScratchStoreManager() {
scratch_->Clear();
scratch_pool_.Push(scratch_);
scratch_pool_.PushNotifyAll();
if (scratch_ != nullptr) {
scratch_->Clear();
scratch_pool_.Push(scratch_);
scratch_pool_.PushNotifyAll();
}
}

void Destroy() {
if (scratch_!= nullptr) {
delete scratch_;
scratch_ = nullptr;
}
while (!scratch_pool_.Empty()) {
auto scratch = scratch_pool_.pop();
auto scratch = scratch_pool_.Pop();
while (scratch == nullptr) {
scratch_pool_.WaitForPushNotify();
scratch = scratch_pool_.pop();
scratch = scratch_pool_.Pop();
}
delete scratch;
}
Expand Down
7 changes: 6 additions & 1 deletion src/storage/knn_index/knn_diskann/vamana_alg.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ public:
}
return *this;
}
~MemVamana() = default;
~MemVamana() {
if (!query_scratch_.Empty()) {
ScratchStoreManager<InMemQueryScratch> manager(query_scratch_);
manager.Destroy();
}
}

static This Make(SizeT L, SizeT R, SizeT dim, SizeT point_num) {
This ret(L, R, dim, point_num);
Expand Down

0 comments on commit 3a094ec

Please sign in to comment.