[ITK] [ITK-users] PyBuffer memory consumption

Harnish, Roy Roy.Harnish at ucsf.edu
Thu Sep 1 18:44:27 EDT 2016


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20160901/621f9574/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PyBufferMem.png
Type: image/png
Size: 13455 bytes
Desc: PyBufferMem.png
URL: <http://public.kitware.com/pipermail/community/attachments/20160901/621f9574/attachment-0001.png>
-------------- next part --------------
_____________________________________
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 Community mailing list