提交 918c1137 编写于 作者: X Xu Peng

fix(db): fix memory leak


Former-commit-id: 1c5b7e0ab18f9508aa5aeecfc7caecf5ac74fd45
上级 97d4738b
...@@ -89,6 +89,7 @@ Status DBImpl::search(const std::string &group_id, size_t k, size_t nq, ...@@ -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, index->add_with_ids(file_index->ntotal,
dynamic_cast<faiss::IndexFlat *>(file_index->index)->xb.data(), dynamic_cast<faiss::IndexFlat *>(file_index->index)->xb.data(),
file_index->id_map.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, ...@@ -220,6 +221,7 @@ Status DBImpl::merge_files(const std::string& group_id, const meta::DateT& date,
updated.push_back(file_schema); updated.push_back(file_schema);
LOG(DEBUG) << "About to merge file " << file_schema.file_id << LOG(DEBUG) << "About to merge file " << file_schema.file_id <<
" of size=" << file_schema.rows; " of size=" << file_schema.rows;
delete file_index;
} }
auto index_size = group_file.dimension * index->ntotal; auto index_size = group_file.dimension * index->ntotal;
...@@ -301,6 +303,8 @@ Status DBImpl::build_index(const meta::GroupFileSchema& file) { ...@@ -301,6 +303,8 @@ Status DBImpl::build_index(const meta::GroupFileSchema& file) {
meta::GroupFilesSchema update_files = {to_remove, group_file}; meta::GroupFilesSchema update_files = {to_remove, group_file};
_pMeta->update_files(update_files); _pMeta->update_files(update_files);
delete from_index;
return Status::OK(); return Status::OK();
} }
......
...@@ -47,7 +47,7 @@ Status MemVectors::serialize(std::string& group_id) { ...@@ -47,7 +47,7 @@ Status MemVectors::serialize(std::string& group_id) {
/* faiss::write_index(pIndex_, _file_location.c_str()); */ /* faiss::write_index(pIndex_, _file_location.c_str()); */
group_id = schema_.group_id; group_id = schema_.group_id;
auto rows = approximate_size(); auto rows = approximate_size();
write_index(pIndex_, schema_.location.c_str()); write_index(pIndex_.get(), schema_.location.c_str());
schema_.rows = rows; schema_.rows = rows;
schema_.file_type = (rows >= options_.index_trigger_size) ? schema_.file_type = (rows >= options_.index_trigger_size) ?
meta::GroupFileSchema::TO_INDEX : meta::GroupFileSchema::RAW; meta::GroupFileSchema::TO_INDEX : meta::GroupFileSchema::RAW;
...@@ -61,10 +61,6 @@ MemVectors::~MemVectors() { ...@@ -61,10 +61,6 @@ MemVectors::~MemVectors() {
delete _pIdGenerator; delete _pIdGenerator;
_pIdGenerator = nullptr; _pIdGenerator = nullptr;
} }
if (pIndex_ != nullptr) {
delete pIndex_;
pIndex_ = nullptr;
}
} }
/* /*
......
...@@ -49,7 +49,7 @@ private: ...@@ -49,7 +49,7 @@ private:
Options options_; Options options_;
meta::GroupFileSchema schema_; meta::GroupFileSchema schema_;
IDGenerator* _pIdGenerator; IDGenerator* _pIdGenerator;
faiss::Index* pIndex_; std::shared_ptr<faiss::Index> pIndex_;
}; // MemVectors }; // MemVectors
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册