[vtkusers] Memory from a vtkImageData after a Delete not being freed
Marcelino Rodriguez Cancio
marcelinorc at uclv.edu.cu
Thu Mar 31 09:26:00 EDT 2011
Hello everyone:
We are working ITK (with a wrapper written by us and seems to be working fine) + VTK with TCL.
We have a little problem in our application with an reference counting not allowing memory to be freed.
I do as follow:
1. Read an ITK image with our ITK wrapper.
2. Create a vtkImageImport
3. Create a new image
4. Do a shallow copy of the vtkImageImport Output to the new image. (Reference counts "jumps" from 1 to 3 in the new image)
5. Delete the vtkImageImport
6. Delete the new imagen
And the memory is not being freed because of the reference counting > 1.
I have reproduced the situation in the following snippet of code:
#itktcl is a package developed by ourselves.
package require itktcl
package require vtk
set infile "D:/data/vtks/smoothing.vtk"
puts "reading image file $infile"
#Read the image with our ITK wrapper.
set reader [ Image3DReader ]
$reader SetFileName $infile
$reader Update
set img [ $reader GetOutput ]
$img DisconnectPipeline
#Destroy the reader
rename $reader ""
#Create a itk exporter
set itkExporter [ VTKScalarImageExport ]
$itkExporter SetInput $img
#Import to VTK
set vtkImporter [ vtkImageImport New ]
$itkExporter Connect2VTK $vtkImporter
$vtkImporter Update
#Do a shallow copy
set cpyImg [vtkImageData New]
$cpyImg ShallowCopy [$vtkImporter GetOutput]
#At this point [$cpyImg GetReferenceCount] == 3!!!
puts "cpyImg->RefCount is: [$cpyImg GetReferenceCount]"
#The follwing crashes!!!:
# $cpyImg UnRegister $ vtkImporter
#The follwing also crashes!!!!:
#$vtkImporter UnRegister $cpyImg
#Cleanup
$vtkImporter Delete
#Destroy the itk exporter
$itkExporter SetInput ""
rename $itkExporter ""
#At this point [$cpyImg GetReferenceCount] is ALSO == 3!!!
puts "cpyImg->RefCount Should be 1 but it is: [$cpyImg GetReferenceCount]"
#Memory it's not being freed!!!
$cpyImg Delete
exit
________________________________
Universidad Central "Marta Abreu" de Las Villas. http://www.uclv.edu.cu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110331/cbc9bd25/attachment.htm>
More information about the vtkusers
mailing list