[Insight-users] itk.PyBuffer memory leak
Rick Giuly
rgiuly at gmail.com
Wed May 13 04:35:30 EDT 2009
I've now tested invoking garbage collection with gc.collect() at every
iteration and that didn't change the problem. So, my best guess would be
that the image is not deleted when the python object is destroyed. Maybe
a bug?
Gaëtan Lehmann wrote:
>
> Hi Rick,
>
> GetImageFromArray() returns a smart pointer to an image, so the image
> should be deallocated once the python object is destroyed.
> Perhaps the problem is there: the garbage collection my not run fast
> enough.
>
> The right way to go may be to implement PyBuffer as a filter which reuse
> the output image, as all the filters in itk.
>
> For the Delete() method: you shouldn't use it in python (and I can't see
> any case for use it but the internal memory management in c++). In the
> latest version of wrapitk (the one hosted at googlecode), Delete() and
> the other methods related to smart pointers are hidden.
>
> Regards,
>
> Gaëtan
>
>
>
> Le 11 mai 09 à 05:43, Rick Giuly a écrit :
>
>>
>> Hello All,
>>
>> It seems that converter.GetImageFromArray(inputNumpyVolume) allocates
>> memory in some way and never releases it. When I tried using Delete()
>> the program actually crashed silently after one iteration.
>>
>> Test code is below. (I'm running this on ubuntu, and the itk package
>> is from Paul Novo's site.)
>>
>> Is there some way to release memory?
>>
>>
>>
>> import itk
>> import numpy
>>
>> for i in range(10000):
>>
>> print i
>>
>> ImageType = itk.Image[itk.F, 3]
>> converter = itk.PyBuffer[ImageType]
>>
>> inputNumpyVolume = numpy.ones((100, 100, 200))
>> inputVolume = converter.GetImageFromArray(inputNumpyVolume)
>> #inputVolume.Delete()
>>
>>
>>
>> ----------
>> Thanks,
>> --Rick
>> _____________________________________
>> 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 ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>
More information about the Insight-users
mailing list