diff --git a/cpp/src/db/DBImpl.cpp b/cpp/src/db/DBImpl.cpp index 19c708dd0b530a02e1a917d61bc6c544d758a515..2fc8e9040078af26f68d635f838be3389002e832 100644 --- a/cpp/src/db/DBImpl.cpp +++ b/cpp/src/db/DBImpl.cpp @@ -89,6 +89,7 @@ Status DBImpl::search(const std::string &group_id, size_t k, size_t nq, index->add_with_ids(file_index->ntotal, dynamic_cast(file_index->index)->xb.data(), file_index->id_map.data()); + delete file_index; } { @@ -220,6 +221,7 @@ Status DBImpl::merge_files(const std::string& group_id, const meta::DateT& date, updated.push_back(file_schema); LOG(DEBUG) << "About to merge file " << file_schema.file_id << " of size=" << file_schema.rows; + delete file_index; } auto index_size = group_file.dimension * index->ntotal; @@ -301,6 +303,8 @@ Status DBImpl::build_index(const meta::GroupFileSchema& file) { meta::GroupFilesSchema update_files = {to_remove, group_file}; _pMeta->update_files(update_files); + delete from_index; + return Status::OK(); } diff --git a/cpp/src/db/MemManager.cpp b/cpp/src/db/MemManager.cpp index 59ae4fd19b71e45127ede17f7197a4539fccc0fe..d1097f40724933362412213fae381b553a69d8c3 100644 --- a/cpp/src/db/MemManager.cpp +++ b/cpp/src/db/MemManager.cpp @@ -47,7 +47,7 @@ Status MemVectors::serialize(std::string& group_id) { /* faiss::write_index(pIndex_, _file_location.c_str()); */ group_id = schema_.group_id; auto rows = approximate_size(); - write_index(pIndex_, schema_.location.c_str()); + write_index(pIndex_.get(), schema_.location.c_str()); schema_.rows = rows; schema_.file_type = (rows >= options_.index_trigger_size) ? meta::GroupFileSchema::TO_INDEX : meta::GroupFileSchema::RAW; @@ -61,10 +61,6 @@ MemVectors::~MemVectors() { delete _pIdGenerator; _pIdGenerator = nullptr; } - if (pIndex_ != nullptr) { - delete pIndex_; - pIndex_ = nullptr; - } } /* diff --git a/cpp/src/db/MemManager.h b/cpp/src/db/MemManager.h index a87c54c14ee960d94b5fca939c74bc696252167b..c99e2be3c1ddd84077059fd009827b2a74b144ff 100644 --- a/cpp/src/db/MemManager.h +++ b/cpp/src/db/MemManager.h @@ -49,7 +49,7 @@ private: Options options_; meta::GroupFileSchema schema_; IDGenerator* _pIdGenerator; - faiss::Index* pIndex_; + std::shared_ptr pIndex_; }; // MemVectors