I have a faiss cpu C++ application on server, and I need to update the index everyday, so I encapsulated the index and search vector into a class and call the destructor every time I update the class member. From the log I print from the server , Im sure the destructor was called every time ,however ,the memory occupied by the service has been growing. Is there any problem about the destructor?
centos 7
Running on:
Interface:
class FaissTool
{
public:
faiss::Index* index;
std::vector<Item> storage_item_vec;
FaissTool(){}
~FaissTool()
{
index->reset();
index=NULL;
printf("release index");
}
};
typedef std::tr1::shared_ptr<FaissTool> FaissToolPtr;
I use a hashmap
basic C++ error
basic C++ error
I find that reset() function in cpu version can only clear data but can not release memory, Am I right?
In case it wasn't clear, with index=NULL you are deliberately dropping the pointer to the index object, not releasing the actual index. If the object is not owned anywhere else, you need to delete it instead (although this means you should also rethink your class's other member functions and constructors, see the rule of three). After that, it's up to the allocator to release the memory back to the system.
//index=NULL;
delete index;
it works,thanks
Most helpful comment
In case it wasn't clear, with
index=NULLyou are deliberately dropping the pointer to the index object, not releasing the actual index. If the object is not owned anywhere else, you need todeleteit instead (although this means you should also rethink your class's other member functions and constructors, see the rule of three). After that, it's up to the allocator to release the memory back to the system.