I’m having memory issues when I loop vtkRenderWindow->Render(). Each render window consists of different Actors. So in the loop, I create the polydata, mapper, actors, renderer and render window.
When I call the render command through the RenderWindow object in the loop, I see the RAM utilization going up. If the loop is big, the RAM blows out. Is there a memory leak issue for the render process? I have used VTK6.3 as well as VTK8.3 and found the same issue.
The issue is most likely that objects are created in the loop. Memory leaks could be prevented by deleting all the objects that were created in the loop, but this design would not work very well even then, because memory allocations/deallocations are computationally very expensive and over time they might cause memory fragmentation, which can further decrease performance and increase memory usage.
Instead, you can create all objects outside the loop and use and update those objects inside the loop.
thanks! it might be the reason. BUT how about the situation that the architecture must be this(alloc and dealloc inside the loop), eg.only create the renderWindow and other resources in server when the client connect and request for the render result, after the client disconnect the renderWindow must be released to reclaimi the memory and GPU memory. Of course, esp when test this with loop that runs many days, there will be many memory fragments. Is there existed method to optimize this situation in VTK? esp in Linux. eg. MemoryPool or optimization for small obejcts allocation?
Thanks!