# vtk how to disable memory extra cost when call render()?

**URL:** https://discourse.vtk.org/t/vtk-how-to-disable-memory-extra-cost-when-call-render/12439
**Category:** Support
**Tags:** rendering, code
**Created:** [October 8, 2023, 1:56am UTC](https://discourse.vtk.org/t/vtk-how-to-disable-memory-extra-cost-when-call-render/12439 "2023-10-08T01:56:11Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ch\_zeng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ch_zeng/32/7799_2.png) [@ch\_zeng](https://discourse.vtk.org/u/ch_zeng)
#### Post date: [October 8, 2023, 1:56am UTC](https://discourse.vtk.org/t/vtk-how-to-disable-memory-extra-cost-when-call-render/12439/1 "2023-10-08T01:56:11Z")

</div>

Hi All,  
after load a vtkdataset,should use the renderWindow-\>Render()。but i found it will have a extra memory cost when the data is more than 100mb。 for example:a vtkdataset size is 500mb ,it’ll cost from 500mb to 1.5G and then fall back to 500mb when render() function called。 although the final memory cost is 500mb,but it will touch 1.5G memory cost . and i found There’s no such thing in paraview.

the only solution I can found is to separate a dataset to vtkMultiBlockDataSet。but i havent test the effects to others(filter:clip slice streamline etc)。

thanks!

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)
#### Post date: [October 9, 2023, 9:01am UTC](https://discourse.vtk.org/t/vtk-how-to-disable-memory-extra-cost-when-call-render/12439/2 "2023-10-09T09:01:33Z")

</div>

Do you have any filters in your pipeline ?  
You may have a look at the [Release Data Flag](https://vtk.org/doc/nightly/html/classvtkDataObject.html#a505ad3440d4b5c2e32df452901ff47ab) option, which allows to release the output of a filter after execution. Of course, re-computation will be needed to get the output of this filter once again, even if no parameters has been changed.

---

<div class="post-metadata">

### Author: ![ch\_zeng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ch_zeng/32/7799_2.png) [@ch\_zeng](https://discourse.vtk.org/u/ch_zeng)
#### Post date: [October 9, 2023, 9:10am UTC](https://discourse.vtk.org/t/vtk-how-to-disable-memory-extra-cost-when-call-render/12439/3 "2023-10-09T09:10:01Z")

</div>

no filters in my pipeline yet,the dataset type is a unstructedgrid,i found use the vtkGeometryFilter can littly reduce the extra memory cost ,but not completely.

```auto
vtkNew<vtkNamedColors> colors;
    vtkNew<vtkDataSetReader> fileReader;
  
    // Read unstructedgrid .vtk file,can replace in your vtk name
    fileReader->SetFileName("direction_3_5000.vtk");
  
    fileReader->Update();

    vtkNew<vtkDataSetMapper> mapper;
    mapper->SetInputData(fileReader->GetOutput());
    vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);

    vtkNew<vtkRenderer> renderer;
    vtkNew<vtkRenderWindow> renderWindow;
    renderWindow->AddRenderer(renderer);
    renderWindow->SetWindowName("test");

    vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
    renderWindowInteractor->SetRenderWindow(renderWindow);

    renderer->AddActor(actor);
    renderer->SetBackground(colors->GetColor3d("DarkOliveGreen").GetData());

    renderWindow->Render();
    renderWindowInteractor->Start();

    return EXIT_SUCCESS;

```

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)
#### Post date: [October 9, 2023, 9:20am UTC](https://discourse.vtk.org/t/vtk-how-to-disable-memory-extra-cost-when-call-render/12439/4 "2023-10-09T09:20:29Z")

</div>

You may want to replace this line:

> [@ch\_zeng](#):
>
> ` mapper->SetInputData(fileReader->GetOutput());`

By:

```auto
mapper->SetInputConnection(fileReader->GetOutputPort());

```

This is the right VTK way to connect filters. Also, this way you can remove the manual `fileReader->Update()` as it will be called automatically by the render. For supported file type, this could allow the reader to only produce a sub-part of the data, the one required for the rendering. I am not sure this will be the case for a `.vtk` file though.

Finally, using `fileReader->SetReleaseDataFlagOn()` , you should clear the output of the reader after it has been used by the mapper.

---

<div class="post-metadata">

### Author: ![ch\_zeng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ch_zeng/32/7799_2.png) [@ch\_zeng](https://discourse.vtk.org/u/ch_zeng)
#### Post date: [October 9, 2023, 9:39am UTC](https://discourse.vtk.org/t/vtk-how-to-disable-memory-extra-cost-when-call-render/12439/5 "2023-10-09T09:39:31Z")

</div>

it seemings works for polydata but not works for unstructedgrid data type by my test。and when read unstructedgrid data,fileReader-\>ReleaseDataFlagOn(); will cause the  
obj disappear。

---

<div class="post-metadata">

### Author: ![ch\_zeng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ch_zeng/32/7799_2.png) [@ch\_zeng](https://discourse.vtk.org/u/ch_zeng)
#### Post date: [October 10, 2023, 5:44am UTC](https://discourse.vtk.org/t/vtk-how-to-disable-memory-extra-cost-when-call-render/12439/6 "2023-10-10T05:44:50Z")

</div>

thanks a lot!Things look like they’re about to settle. i have the last question is about the normal way to deal with unstructedgrid,shall i use the vtkgeometryfilter to extract surface polydata to surface rendering and use the original dataset(unstructedgrid type) to deal with filters（slice,cut,streamline,glyph,resamplewithdataset,etc）？and when use unstructedgrid vtkdataset, it looks like i should use vtkgeometryfilter to extract polydata tosurface rendering everytime when the filter output is not polydata? thanks again.

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)
#### Post date: [October 18, 2023, 1:04pm UTC](https://discourse.vtk.org/t/vtk-how-to-disable-memory-extra-cost-when-call-render/12439/7 "2023-10-18T13:04:12Z")

</div>

@ch_zeng  
You are right, you should use the unstructured grid as input for your processing filters, whenever you need to process the full 3D domain.  
The geometry filter is a way to get a simple surface (polydata) suited for surface rendering. So when you want to do surface rendering, having a geometry filter and a polydata mapper is indeed the way to go.

One example of rendering that would **not** work with the geometry filter, would be volumic rendering.
