[vtkusers] vtkImageImport memory not freed

Aron Helser aron.helser at kitware.com
Sun Jun 4 15:30:54 EDT 2017


Instead of a DeepCopy, I think you may want ShallowCopy - IIRC, it detaches
the imageImport like you want, but doesn't copy the data.
I remember seeing this go by on a blog post or email, so please
double-check me :)
Aron

On Sun, Jun 4, 2017 at 8:44 AM, kenichiro yoshimi <rccm.kyoshimi at gmail.com>
wrote:

> Hi,
>
> I am not sure, but it looks like vtkImageReader2 can read a raw volume
> directly from a file without using a temporary variable. Would the
> vtkImageReader2 reader solve your problem?
>
> Thanks,
>
> 2017-06-04 7:16 GMT+09:00 Mike Withascarf via vtkusers <vtkusers at vtk.org>:
> > 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;
> > }
> >
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the VTK FAQ at:
> > http://www.vtk.org/Wiki/VTK_FAQ
> >
> > Search the list archives at: http://markmail.org/search/?q=vtkusers
> >
> > Follow this link to subscribe/unsubscribe:
> > http://public.kitware.com/mailman/listinfo/vtkusers
> >
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170604/a3265219/attachment.html>


More information about the vtkusers mailing list