[vtkusers] How to prevent out-of-memory crash with vtkImageReader from Java
Sebastien Jourdain
sebastien.jourdain at kitware.com
Wed Oct 15 10:30:04 EDT 2014
Hi Marco,
I don't have the answer but if there is no solution as today, maybe adding
another method on the reader that could first validate that enough memory
is available, might be an option. Specially in Java when such call make the
JVM crash.
That change will need to happen on the C++ side. But at that point I'm not
sure how to check that on the C++ side either. Maybe Berk, Dave or Brad
might have some insight.
Thanks,
Seb
On Wed, Oct 15, 2014 at 3:04 AM, Marco Sambin <m.sambin at gmail.com> wrote:
> Hi all.
> In my VTK-based Java application, I am reading a "raw volume file"
> (containing a set of CT slices) through some Java code looking like this:
>
> [...]
> vtkImageReader imageReaderVTK = new vtkImageReader();
> imageReaderVTK.FileLowerLeftOn();
> imageReaderVTK.SetFileDimensionality(3);
> imageReaderVTK.SetFileName(curRawVolFile.getAbsolutePath());
> imageReaderVTK.SetDataExtent(0, sliceCols - 1,
> 0, sliceRows - 1,
> 0, numOfUsedImages - 1);
> imageReaderVTK.SetDataSpacing(xSpacing, ySpacing, zSpacing);
> imageReaderVTK.SetDataOrigin(0.0, 0.0, 0.0);
> imageReaderVTK.SetDataScalarTypeToUnsignedShort();
> imageReaderVTK.SetDataByteOrderToBigEndian();
>
> // The following call may cause a process crash due to out-of-memory
> imageReaderVTK.UpdateWholeExtent();
> [...]
>
> I am then passing this volume to a vtkImagePlaneWidget for some reslicing.
>
> As the last comment (in the code fragment above) suggests, in some cases I
> get a crash of the JVM process, due to the fact the reader goes out of
> memory while actually reading and allocating the whole volume in memory.
> This especially happens when using a 32-bit JRE.
> I understand that I cannot read a huge volume in memory if just a small
> amount of memory is available to the process, but my question is:
> is there a way to manage "more gracefully" this out-of-memory from Java
> code, in such a way to be able to inform the user that "Not enough memory
> is available to read this volume", instead of causing a JVM crash?
>
> I am using VTK 6.1.0.
>
> Thanks for any hint/suggestion about this topic.
>
> Best regards,
>
> Marco
>
>
> _______________________________________________
> 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
>
> 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/20141015/04ad81be/attachment.html>
More information about the vtkusers
mailing list