My program as a service, so it needs to continuously create different vtkxxxReader
instances and read in files. However, I’m currently facing two issues.
- Even after the use of
vtkxxxxReader
has ended, the memory is not completely released. - When using the VTK libraries in ParaView, such as
vtkMEDReader
, memory usage increases with multiple calls.
void readerFile() {
vtkNew<vtkMEDReader> m_reader;
m_reader->SetFileName(InputFile);
m_reader->Update();
}
long long getProcessMemoryInfo(pid_t pid, const std::string &key){...} // Get the current memory occupied by the process
int main()
{
pid_t pid = getpid();
int counter = 5;
while (counter--) {
std::cout << "Start RSS = "<<getProcessMemoryInfo(pid, "VmRSS")<< std::endl;
readerFile();
std::cout << "End RSS = "<<getProcessMemoryInfo(pid, "VmRSS")<< std::endl;
}
return 0;
}
After creating the reader container in VTK, passing in the file name, and calling the Update
function, when the lifecycle of the container ends (while the overall process has not terminated), the memory occupied is not fully released.
I have already tried the following methods, but none of them have been effective:
- Adding
m_reader.Reset();
- Switching to
vtkSmartPointer
- Manually managing memory in the traditional C++ way:
vtkMEDReader* m_reader = vtkMEDReader::New(); m_reader->Delete();