[ITK-users] Memory leak in Python wrapped Image GetPixel method?

Paavolainen, Lassi lassi.paavolainen at jyu.fi
Mon Mar 9 06:11:55 EDT 2015


Hi,

I noticed that GetPixel method in itk.Image object eats memory in Python wrapped code. I think I've seen some Python wrapping memory issues years ago but nothing as simple as this. Here is a simple test script:
import sys
import itk
reader = itk.ImageFileReader.IUC2.New()
reader.SetFileName(sys.argv[1])
reader.Update()
img = reader.GetOutput()
size = img.GetLargestPossibleRegion().GetSize()
for i in range(100):
	for x in range(size[0]):
		for y in range(size[1]):
			value = img.GetPixel((x,y))
	print "Done with iteration %d"%(i+1)

When I run it with 1 MB image, it end up taking 1.5 GB of memory. After spending lots of time on debugging a bigger bunch of code I realized that the GetPixel method was to blame. Can anyone reproduce it? I'm using ITK 4.6.1

Cheers,
Lassi


More information about the Insight-users mailing list