[vtk-developers] Two memory leaks in rendering

Clinton Stimpson clinton at elemtech.com
Thu Apr 26 00:45:02 EDT 2012


Here's a fix for the leaks from the mousePressEvent.
http://review.source.kitware.com/#/c/5360/
Its based off the release branch in case there is time to merge it.

I'm still unable to reproduce leaks from your mouseMoveEvent() code, but you could try again after applying the patch to fix the other one.
Or maybe someone else can report whether they see that leak.

Clint

On Apr 25, 2012, at 7:44 PM, Jonathan Morra wrote:

> I have posted a version of this program to the users mailing list before but got minimal response.  Since I have discovered a different memory leak in rendering.  These two memory leaks are making my program extremely unstable, as they get magnified when rendering large objects.  I'm stuck in my development cycle until these rendering issues get resolved, as a result I am very motivated to provide any extra comments, data, work that I can to help fix this problem.
> 
> Reproduced below is a test program that causes 2 memory issues in Windows 7 (both x86 and x64).  Please let me know if you can reproduce these problems or not, and if you can fix them.  Currently I'm hooking in GDCM as well (although not in this test program), so I cannot easily move to VTK 6 as GDCM currently does not compile for VTK 6, so if these bugs can be fixed on the release branch, that would be amazing.
> 
> Again, please contact me if you have any questions or would like more information.
> 
> Thanks
> 
> #include <QtGui/QApplication>
> #include <QMainWindow>
> #include <QVTKWidget2.h>
> #include <vtkImageViewer2.h>
> #include <vtkImageData.h>
> #include <vtkPointData.h>
> #include <vtkGenericOpenGLRenderWindow.h>
> #include <vtkSphereSource.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkActor.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindow.h>
> // This program shows 2 separate bugs with rendering.
> /**
>   First, if you run the program as provided, and either move the mouse over the image
>   or press the mouse, notice that the memory stays constant.  The first bug involves consuming memory
>   on a render command when we're just rendering an image.  In order to see this, comment in the
>   commented out line in the mouseMoveEvent method.  Notice that as you mouse around the memory now increases.
>   The second bug involves rendering after an actor has been added.  If you comment in the one 
>   commented out line in mousePressEvent, you now see the memory jump significantly after each
>   mouse press.
>   
>   I'm testing these on Qt 4.8.0 x64 Windows VS 2008, VTK pulled from git release branch, tag 
>   5.10.0-rc1.  I'm monitoring the memory using the Windows Task Manager.
>   */
> class MyQVTKWidget2 : public QVTKWidget2 {
>     vtkSmartPointer<vtkRenderer> renderer;
> public:
>     MyQVTKWidget2 (vtkSmartPointer<vtkImageViewer2> imageViewer, QWidget *parent = 0) : QVTKWidget2(parent) {
>         this->imageViewer = imageViewer;
>         renderer = vtkSmartPointer<vtkRenderer>::New();
>         GetRenderWindow()->AddRenderer(renderer);
>     }
>     virtual ~MyQVTKWidget2() {
>     }
>     void mouseMoveEvent(QMouseEvent *) {
>         for (int i=0; i<1000; ++i) {
>             //imageViewer->Render();
>         }
>     }
>     void mousePressEvent(QMouseEvent *) {
>         vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
>         sphereSource->Update();
>         for (int i=0; i<1000; ++i) {
>             vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
>             mapper->SetInput(sphereSource->GetOutput());
>             mapper->Update();
>             vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
>             actor->SetMapper(mapper);
>             renderer->AddActor(actor);
>             //renderer->Render();
>             renderer->RemoveActor(actor);
>         }
>     }
> private:
>     vtkSmartPointer<vtkImageViewer2> imageViewer;
> };
> int main(int argc, char *argv[]) {
>     QApplication a(argc, argv);
>     vtkSmartPointer<vtkImageData> imageData = vtkSmartPointer<vtkImageData>::New();
>     imageData->SetExtent(0, 100, 0, 100, 0, 100);
>     imageData->SetOrigin(0, 0, 0);
>     imageData->SetSpacing(1, 1, 1);
>     imageData->AllocateScalars();
>     imageData->GetPointData()->GetScalars()->FillComponent(0, 0);
>     vtkSmartPointer<vtkImageViewer2> imageViewer = vtkSmartPointer<vtkImageViewer2>::New();
>     imageViewer->SetInput(imageData);
>     MyQVTKWidget2 *widget = new MyQVTKWidget2(imageViewer);
>     imageViewer->SetRenderWindow(widget->GetRenderWindow());
>     QMainWindow mainWindow;
>     mainWindow.setGeometry(200, 200, 300, 300);
>     mainWindow.setCentralWidget(widget);
>     mainWindow.show();
>     return a.exec();
> }
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20120425/eea30bef/attachment.html>


More information about the vtk-developers mailing list