[vtkusers] Memory leaks

Alex Malyushytskyy alexmalvtk at gmail.com
Thu Dec 1 16:53:07 EST 2011


You don't provide all the code, not even function declarations, so
there is no way to check where/if you get memory leak..
Leak if

Personally I find using vtkSmartPointer not intuitive in then most
cases when pointer does not get out of scope mostly immediately,
especially due to the fact that all the vtk api oriented on the
regular pointer usage.

About second question ( releasing unneeded resources, you might find answers at:
http://www.itk.org/Wiki/VTK/FAQ#How_to_handle_large_data_sets_in_VTK

Personally I use different method which achieve similar effect , see
example below
and check calls to:
		poly->Register(NULL);
		poly->SetSource(NULL);


vtkPolyData* createPolyDataFromVtkFile( const QString& fileName )
{
	vtkPolyData* poly = NULL;
	Q_ASSERT( !fileName.isEmpty() );

	if( ! fileName.isEmpty() )
	{
		QByteArray byteArray = QFile::encodeName ( fileName );

		vtkXMLPolyDataReader * sr = vtkXMLPolyDataReader ::New();
		sr->SetFileName( byteArray.data() );
		sr->Update();

		// make poly forget about the way it was created and release all the
vtkObjects
		poly = sr->GetOutput();
		poly->Register(NULL);
		poly->SetSource(NULL);

		sr->Delete();

#ifdef DEBUG_POLY_DATA_MEMORY_LEAKS
		poly->DebugOn();
#endif
	}

	return poly;
}


On Thu, Dec 1, 2011 at 12:18 AM, Jose Navas <josenavasmolina at hotmail.com> wrote:
> Hi all,
>
> I am developing a medical application which allows the user to generate
> several times the same polyData but changing some attributes like marching
> cubes' isovalue or to apply/not to apply some filter, such as
> vtkPolyDataConnectivityFilter. Here is a structure of my code:
>
> class Model{
>     ...
>     vtkSmartPointer<vtkPolyData> mMesh;
>     ...
> }
>
> void Model::generateMesh(double isovalue, bool connected)
> {
>     mMesh = generateMarchingCubesMesh(isovalue, someVtkImageData)
>     if(connected) mMesh = getLargestConnectedMesh(mMesh)
>     // connect to rendering pipeline....
> }
>
> Where:
>   - generateMarchingCubesMesh is a function that returns a
> vtkSmartPointer<vtkPolyData> and executes vtkMarchingCubes and
> vtkTriangleFilter
>   - getLargestConnectedMesh is a function that returns a
> vtkSmartPointer<vtkPolyData> and executes vtkPolyDataConnectivityFilter
>
> When the user regenerates the mesh, the existing structures are not deleted
> and don't release memory, so what I have to do to release all these memory?
>
> Another question is if there is any way to not to hold all the structures
> (vtkMarchingCubes, vtkTriangleFilter, etc...) used to propagate the update()
> call upstream, due to the user don't changes changes the vtkImageData
> source. In other words, how to delete all the structures once the resulting
> vtkPolyData is generated?
>
> Thanks,
>
> Jose
>
> _______________________________________________
> 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