[vtkusers] VTK not releasing memory, including minimal example.
Alex Malyushytskyy
alexmalvtk at gmail.com
Mon Oct 1 19:07:40 EDT 2012
Pure C++ shows that you did not call Delete for at least:
vtkCallbackCommand *middle_callback = vtkCallbackCommand::New();
vtkCallbackCommand *right_callback = vtkCallbackCommand::New();
Make sure every ::New() is paired with Delete or use smart pointers.
I have no experience with Python but I tell you that for about 10
years of using vtk
I found a single memory leak in it, so look for a problem ion your code first.
Alex
On Sun, Sep 30, 2012 at 2:38 PM, P.J.Schaafsma
<jetze.schaafsma at gmail.com> wrote:
> Pure C++ shows the same problems, so Python isn't a factor either.
>
> C++ code
>
>
> #include <stdio.h>
> #include <crtdbg.h>
>
> #include "vtkConeSource.h"
> #include "vtkPolyDataMapper.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkCamera.h"
> #include "vtkActor.h"
> #include "vtkRenderer.h"
> #include "vtkInteractorStyleTrackballCamera.h"
> #include "vtkContourFilter.h"
> #include "vtkXMLImageDataReader.h"
> #include "vtkPolyDataMapper.h"
> #include "vtkCallbackCommand.h"
>
> void middle(vtkObject*, unsigned long eid, void* clientdata, void *calldata)
> {
> void **data = (void **)clientdata;
>
> vtkXMLImageDataReader *reader = (vtkXMLImageDataReader *)data[0];
> vtkContourFilter *contour = (vtkContourFilter *)data[1];
> vtkPolyDataMapper *mapper = (vtkPolyDataMapper *)data[2];
> vtkActor *actor = (vtkActor *)data[3];
> vtkRenderer *renderer = (vtkRenderer *)data[4];
>
> renderer->RemoveActor(actor);
>
> printf("actor RC: %d\n", actor->GetReferenceCount());
> printf("mapper RC: %d\n", mapper->GetReferenceCount());
> printf("contour RC: %d\n", contour->GetReferenceCount());
> printf("reader RC: %d\n", reader->GetReferenceCount());
>
> actor->Delete();
> mapper->Delete();
> contour->Delete();
> reader->Delete();
>
> printf("actor RC: %d\n", actor->GetReferenceCount());
> printf("mapper RC: %d\n", mapper->GetReferenceCount());
> printf("contour RC: %d\n", contour->GetReferenceCount());
> printf("reader RC: %d\n", reader->GetReferenceCount());
>
> }
>
> void right(vtkObject*, unsigned long eid, void* clientdata, void *calldata)
> {
> void **data = (void **)clientdata;
>
> vtkXMLImageDataReader *reader = (vtkXMLImageDataReader *)data[0];
> vtkContourFilter *contour = (vtkContourFilter *)data[1];
> vtkPolyDataMapper *mapper = (vtkPolyDataMapper *)data[2];
> vtkActor *actor = (vtkActor *)data[3];
> vtkRenderer *renderer = (vtkRenderer *)data[4];
>
> reader->SetFileName("e:\\data\\volume\\manix_low.vti");
> //reader->SetFileName("/media/Data/data/volume/manix_low.vti");
>
> contour->SetInputConnection(reader->GetOutputPort());
> contour->SetValue(0, 800);
>
> mapper->SetInputConnection(contour->GetOutputPort());
>
> actor->SetMapper(mapper);
>
> renderer->AddActor(actor);
> renderer->ResetCamera();
>
> }
>
> int main()
> {
> vtkCamera *camera = vtkCamera::New();
>
> vtkRenderer *renderer = vtkRenderer::New();
> renderer->SetActiveCamera(camera);
>
> vtkRenderWindow *render_window = vtkRenderWindow::New();
> render_window->AddRenderer(renderer);
>
> vtkInteractorStyleTrackballCamera *style =
> vtkInteractorStyleTrackballCamera::New();
>
> vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
> interactor->SetInteractorStyle(style);
> interactor->SetRenderWindow(render_window);
> interactor->Initialize();
>
> vtkXMLImageDataReader *reader = vtkXMLImageDataReader::New();
> vtkContourFilter *contour = vtkContourFilter::New();
> vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
> vtkActor *actor = vtkActor::New();
>
> void *data[] = {reader, contour, mapper, actor, renderer};
>
> vtkCallbackCommand *middle_callback = vtkCallbackCommand::New();
> middle_callback->SetCallback(middle);
> middle_callback->SetClientData(data);
>
> vtkCallbackCommand *right_callback = vtkCallbackCommand::New();
> right_callback->SetCallback(right);
> right_callback->SetClientData(data);
>
> interactor->AddObserver("MiddleButtonPressEvent", middle_callback);
> interactor->AddObserver("RightButtonPressEvent", right_callback);
>
> interactor->Start();
>
> render_window->RemoveRenderer(renderer);
> interactor->SetInteractorStyle(0);
>
> style->Delete();
> camera->Delete();
> interactor->Delete();
> renderer->Delete();
> render_window->Delete();
>
> return 0;
> }
>
>
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/VTK-not-releasing-memory-including-minimal-example-tp5716258p5716368.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> 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://www.vtk.org/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list