<html><head></head><body><div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px"><div dir="ltr" id="yui_3_16_0_1_1496527844944_2943">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!</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2949"><br></div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2882">vtkSmartPointer<vtkImageData> load_image(const std::string &fn)</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2883">{</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2884"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2885">   </span>unsigned long long size = 6144000000;</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2886"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2887"> </span>int dims[3]{ 800, 600, 6400 };</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2888"><br id="yui_3_16_0_1_1496527844944_2889"></div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2890"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2891">     </span>// load data</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2892"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2893">  </span>ifstream fs(fn, ifstream::binary);</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2894"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2895">    </span>char* data = new char[size];</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2896"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2897">  </span>fs.read(data, size);</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2898"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2899">  </span>fs.close();</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2900"><br id="yui_3_16_0_1_1496527844944_2901"></div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2902"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2903">        </span>// vtk import</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2904"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2905"> </span>vtkSmartPointer<vtkImageImport> image_import = vtkSmartPointer<vtkImageImport>::New();</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2906"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2907">    </span>image_import->SetDataSpacing(1, 1, 1);</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2908"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2909">     </span>image_import->SetDataOrigin(0, 0, 0);</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2910"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2911">      </span>image_import->SetWholeExtent(0, dims[0] - 1, 0, dims[1] - 1, 0, dims[2] - 1);</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2912"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2913">      </span>image_import->SetDataExtentToWholeExtent();</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2914"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2915">        </span>image_import->SetDataScalarTypeToUnsignedShort();</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2916"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2917">  </span>image_import->SetNumberOfScalarComponents(1);</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2918"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2919">      </span>image_import->SetImportVoidPointer(data);</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2920"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2921">  </span>image_import->Update();</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2922"><br id="yui_3_16_0_1_1496527844944_2923"></div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2924"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2925"> </span>// This works, but the memory will never be released even when the vtkImageData is deleted</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2926"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2927">    </span>return image_import->GetOutput();</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2928"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2929">  </span></div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2930"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2931">      </span>// This prevents memory leaks, but means that I need twice the memory available for a brief moment</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2932"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2933">    </span>vtkSmartPointer<vtkImageData> im = vtkSmartPointer<vtkImageData>::New();</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2934"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2935">  </span>im->DeepCopy(image_import->GetOutput());</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2936"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2937">        </span>delete[] data;</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2938"><span style="white-space:pre-wrap;" id="yui_3_16_0_1_1496527844944_2939">        </span>return im;</div><div dir="ltr" id="yui_3_16_0_1_1496527844944_2940">}</div></div></body></html>