[vtkusers] remove vtkActor,can not free the memery

forgy peng forgypeng at gmail.com
Sat Nov 26 03:29:55 EST 2011


> Hi everyone:
>      I have got a problem when i try to remove a vtkActor and free the
> memery.As you can see, I add some actors to the render and I removed them
> and delete them,but the memery does not free.But when i delete   "*
> this->m_render->AddActor(actor);*"  the problem was gone! Does anyone
> know how can I fix it?
>     Here is the code:
>
> -----------------------------------------------------------------------------
>     m_render = vtkRenderer::New();
>     vtkRenderWindow *renWin = vtkRenderWindow::New();
>     renWin->StereoCapableWindowOn();
>      ui->qvtkWidget->SetRenderWindow(renWin);
>     renWin->AddRenderer(m_render);
>     m_render->SetBackground(0.1, 0.2, 0.4);
>     renWin->Render();
>
>     connect(this->ui->pushButton,SIGNAL(clicked()),this,SLOT(release()));
>     QString folder = QFileDialog::getExistingDirectory();
>     QDir dir(folder);
>     dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
>
>     foreach(QFileInfo info,dir.entryInfoList())
>     {
>         QString fileName = info.absoluteFilePath();
>         char *name = fileName.toUtf8().data();
>         std::ifstream ifs;
>         if ( !liblas::Open(ifs, name))
>         {
>             return;
>         }
>
>         vtkPoints *points = vtkPoints::New();
>         liblas::Reader reader(ifs);
>
>         while( reader.ReadNextPoint() )
>         {
>             liblas::Point  point = reader.GetPoint();
>
> points->InsertNextPoint(point.GetX(),point.GetY(),point.GetZ());
>         }
>         ifs.close();
>         vtkCellArray *cell = vtkCellArray::New();
>         int num = points->GetNumberOfPoints();
>         cell->InsertNextCell(num);
>         for(int i = 0; i< num; i++)
>         {
>             cell->InsertCellPoint(i);
>         }
>
>         vtkPolyData *polyData = vtkPolyData::New();
>         polyData->SetPoints(points);
>         polyData->SetVerts(cell);
>
>         vtkPolyDataMapper* mapper =
> vtkPolyDataMapper::New();
>         mapper->SetInput(polyData);
>         vtkActor *actor = vtkActor::New();
>         actor->SetMapper(mapper);
>         this->m_actors.insert(fileName,actor);
>        * this->m_render->AddActor(actor);*// when i delete this ,the
> memery can be free,Why?
>
>         mapper->Delete();
>         polyData->Delete();
>         cell->Delete();
>         points->Delete();
>         renWin->Render();
>     }
>     foreach(QString file,this->m_actors.keys())
>     {
>         vtkActor *actor = this->m_actors[file];
>         this->m_actors.remove(file);
>         actor->Delete();
>         actor=NULL;
>     }
>
> ---------------------------------------------------------------------------
>     Thank you!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111126/a5436069/attachment.htm>


More information about the vtkusers mailing list