[vtkusers] Deleting unknown object
David Doria
daviddoria+vtk at gmail.com
Wed Oct 14 07:26:51 EDT 2009
I'm having trouble cleaning up memory leaks in some code. Here is an
example:
#include <vtkMutableUndirectedGraph.h>
#include <vtkBoostPrimMinimumSpanningTree.h>
#include <vtkTree.h>
#include <iostream>
#include <string>
int main(int argc, char *argv[])
{
vtkMutableUndirectedGraph* G = vtkMutableUndirectedGraph::New();
//create 3 vertices
vtkIdType V1 = G->AddVertex();
vtkBoostPrimMinimumSpanningTree* MinimumSpanningTreeFilter =
vtkBoostPrimMinimumSpanningTree::New();
MinimumSpanningTreeFilter->SetOriginVertex(V1);
MinimumSpanningTreeFilter->SetInput(G);
vtkTree* MinimumSpanningTree = vtkTree::New();
MinimumSpanningTree = MinimumSpanningTreeFilter->GetOutput();
//cleanup
//G->Delete(); //works ok
//MinimumSpanningTreeFilter->Delete(); //works ok
MinimumSpanningTree->Delete(); //deleting unknown object: vtkDataObject -
segfault
return 0;
}
>From what I understand, you should call Delete() on everything that you
called New() on. That seems to work in most cases (G and
MinimumSpanningTreeFilter) in the above example. However, in some cases when
I call Delete I get a segfault and a warning from vtkDebugLeaks about
deleting an unknown object (as with MinimumSpanningTree in the above
example).
Am I misunderstanding when/how to delete these things?
Thanks,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091014/e94f1901/attachment.htm>
More information about the vtkusers
mailing list