[ITK-users] PyBuffer memory consumption
Harnish, Roy
Roy.Harnish at ucsf.edu
Fri Sep 23 16:53:32 EDT 2016
Hi Matt,
Many thanks for taking a look and finding a solution!
Roy
________________________________________
From: Matt McCormick [matt.mccormick at kitware.com]
Sent: Wednesday, September 21, 2016 7:15 AM
To: Harnish, Roy
Cc: insight-users at itk.org
Subject: Re: [ITK-users] PyBuffer memory consumption
Hi Roy,
Thanks for bringing the issue up again and sharing testing code.
The issue has been addressed here:
https://github.com/InsightSoftwareConsortium/ITKBridgeNumPy/commit/4d006eb39d2eb1db13a3f7ce6e639ee715d4360e
including a test based off your code.
It will be added to ITK with this patch:
http://review.source.kitware.com/#/c/21556/
Thanks,
Matt
On Thu, Sep 1, 2016 at 6:44 PM, Harnish, Roy <Roy.Harnish at ucsf.edu> wrote:
> Hi Again,
>
> I've played with it more and have another example that shows differences in
> memory usage depending on the interplay between calls to numpy.ones() and
> converter.GetImageFromArray(inputNumpyVolume):
>
> import itk
> import numpy as np
> import resource
> import matplotlib.pyplot as plt
>
> ImageType = itk.Image[itk.D, 3]
> converter = itk.PyBuffer[ImageType]
>
> # adding +1 to numpy created once
> inputNumpyVolume = np.ones([100,100,100])
> M = []
> n = 10
> for i in range(n):
>
> inputNumpyVolume += 1
> inputVolume = converter.GetImageFromArray(inputNumpyVolume)
> M.append(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
>
> X = range(n)
> plt.plot(X,M,'o', color='red')
>
> # creating new numpy volume each time
> M = []
> for i in range(n):
>
> inputNumpyVolume = np.ones([100,100,100])
> inputVolume = converter.GetImageFromArray(inputNumpyVolume)
> M.append(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
>
> X = [x + n for x in range(n)]
> plt.plot(X,M,'o', color='green')
>
> # creating new numpy volume but not calling
> converter.GetImageFromArray(inputNumpyVolume)
> M = []
> for i in range(n):
>
> inputNumpyVolume = np.ones([100,100,100])
> M.append(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
>
> X = [x + 2*n for x in range(n)]
> plt.plot(X,M,'o', color='blue')
>
> plt.savefig("PyBufferMem.png")
> plt.show()
>
> Thanks for taking a look.
>
> Roy
> ________________________________
> From: Insight-users [insight-users-bounces at itk.org] on behalf of Harnish,
> Roy [Roy.Harnish at ucsf.edu]
> Sent: Thursday, September 01, 2016 2:39 PM
> To: insight-users at itk.org
> Subject: [ITK-users] PyBuffer memory consumption
>
> Hi,
>
> I'm resurrecting a thread that I ran across trying to debug what looks to be
> a memory leak when using PyBuffer:
>
> https://itk.org/pipermail/insight-users/2009-May/030386.html
>
> If I repeatedly assign the output of
> itk.PyBuffer[ImageType].GetImageFromArray() to the same python variable
> name, more and more memory is consumed by the process. Wondering if anyone
> knows how to get this memory released? Here's some example code based on the
> linked thread that should reproduce the problem:
>
> import itk
> import numpy as np
> import resource
>
> M = []
>
> for i in range(200):
>
> M.append(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
>
> ImageType = itk.Image[itk.D, 3]
> converter = itk.PyBuffer[ImageType]
>
> inputNumpyVolume = np.ones((100, 100, 100))
> inputVolume = converter.GetImageFromArray(inputNumpyVolume)
> # inputVolume.Delete()
>
> print M
>
> Any suggestions much appreciated.
>
> Roy
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> 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://public.kitware.com/mailman/listinfo/insight-users
>
More information about the Insight-users
mailing list