Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PQScratch memory leak #522

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/pq_scratch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ template <typename T> class PQScratch

PQScratch(size_t graph_degree, size_t aligned_dim);
void initialize(size_t dim, const T *query, const float norm = 1.0f);
virtual ~PQScratch();
};

} // namespace diskann
4 changes: 4 additions & 0 deletions src/pq_flash_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ template <typename T, typename LabelT> PQFlashIndex<T, LabelT>::~PQFlashIndex()
{
delete[] _pts_to_labels;
}
if (_medoids != nullptr)
{
delete[] _medoids;
}
}

template <typename T, typename LabelT> inline uint64_t PQFlashIndex<T, LabelT>::get_node_sector(uint64_t node_id)
Expand Down
11 changes: 10 additions & 1 deletion src/scratch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ template <typename T> SSDQueryScratch<T>::~SSDQueryScratch()
diskann::aligned_free((void *)sector_scratch);
diskann::aligned_free((void *)this->_aligned_query_T);

delete[] this->_pq_scratch;
delete this->_pq_scratch;
}

template <typename T>
Expand All @@ -143,6 +143,15 @@ template <typename T> PQScratch<T>::PQScratch(size_t graph_degree, size_t aligne
memset(rotated_query, 0, aligned_dim * sizeof(float));
}

template <typename T> PQScratch<T>::~PQScratch()
{
diskann::aligned_free((void *)aligned_pq_coord_scratch);
diskann::aligned_free((void *)aligned_pqtable_dist_scratch);
diskann::aligned_free((void *)aligned_dist_scratch);
diskann::aligned_free((void *)aligned_query_float);
diskann::aligned_free((void *)rotated_query);
}

template <typename T> void PQScratch<T>::initialize(size_t dim, const T *query, const float norm)
{
for (size_t d = 0; d < dim; ++d)
Expand Down
Loading