[vtkusers] VTK not releasing memory, including minimal example.
P.J.Schaafsma
jetze.schaafsma at gmail.com
Sun Sep 30 17:38:57 EDT 2012
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.
More information about the vtkusers
mailing list