Skip to content

Commit

Permalink
fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
luyuncheng authored Mar 4, 2024
1 parent a25ee6f commit d5207b7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
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
9 changes: 9 additions & 0 deletions src/scratch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d5207b7

Please sign in to comment.