[vtkusers] remove vtkActor,can not free the memery

David Doria daviddoria at gmail.com
Sat Nov 26 07:35:06 EST 2011


On Sat, Nov 26, 2011 at 3:29 AM, forgy peng <forgypeng at gmail.com> wrote:
>
>> 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!

I would try renderer->RemoveViewProp(actor) before you try to delete
the actor. Let us know if that helps.

David



More information about the vtkusers mailing list