[vtkusers] vtkImageImport memory not freed

Mike Withascarf mikewithascarf at yahoo.com
Sat Jun 3 18:16:54 EDT 2017


Hi, I'm attempting to use vtkImageImport on an array in a function to return a vtkImageData. It works, but once the vtkImageData is deleted the memory is not freed unless I do a DeepCopy in the function for loading it. Unfortunately if I do a DeepCopy it momentarily doubles the amount of memory needed which is really bad for the large data sizes we are using. Here is a stripped down version of the function I'm using. Any help would be very appreciated!
vtkSmartPointer<vtkImageData> load_image(const std::string &fn){ unsigned long long size = 6144000000; int dims[3]{ 800, 600, 6400 };
 // load data ifstream fs(fn, ifstream::binary); char* data = new char[size]; fs.read(data, size); fs.close();
 // vtk import vtkSmartPointer<vtkImageImport> image_import = vtkSmartPointer<vtkImageImport>::New(); image_import->SetDataSpacing(1, 1, 1); image_import->SetDataOrigin(0, 0, 0); image_import->SetWholeExtent(0, dims[0] - 1, 0, dims[1] - 1, 0, dims[2] - 1); image_import->SetDataExtentToWholeExtent(); image_import->SetDataScalarTypeToUnsignedShort(); image_import->SetNumberOfScalarComponents(1); image_import->SetImportVoidPointer(data); image_import->Update();
 // This works, but the memory will never be released even when the vtkImageData is deleted return image_import->GetOutput();  // This prevents memory leaks, but means that I need twice the memory available for a brief moment vtkSmartPointer<vtkImageData> im = vtkSmartPointer<vtkImageData>::New(); im->DeepCopy(image_import->GetOutput()); delete[] data; return im;}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170603/ba0d1d44/attachment.html>


More information about the vtkusers mailing list