Skip to content

Possible memory leak in ui.ImageView #244

@rebryant

Description

@rebryant

I am trying to create animations by displaying a sequence of JPG images. My code consistently crashes Pythonista after a few hundred images. By "crash" I mean that Pythonista silently exits, and when restarting the app, the console session is empty.

I suspect that there's a memory leak. When replacing the ImageView image, the old one doesn't get dereferenced, and so the app runs out of memory.

Here's some code that demonstrates the problem:


import ui
import urllib

class GUI:
    mainView = None
    imageView = None
    images = ['im1.jpg', 'im2.jpg', 'im3.jpg']
    afile = "log.txt"
    url = "http://www.cs.cmu.edu/~bryant/"

    def __init__(self):
        iwidth = 2048
	iheight = 1536
        width = iwidth/4
        height = iheight/4
        self.mainView = ui.View(frame=(0,0,width,height))
        self.imageView = ui.ImageView(frame=(0,0,width,height))
	self.imageView.center = (width/2,height/2)
        self.mainView.add_subview(self.imageView)
        self.mainView.present('sheet')
        self.download()

    def download(self):
        for iname in self.images:
            url = self.url + iname
            urllib.urlretrieve(url, iname)
            print "Downloaded %s" % url

    def archive(self, msg):
        print msg
        f = open(self.afile, "a")
        f.write(msg + "\n")
        f.close()

    def run(self):
        for count in xrange(2000):
            iname = self.images[count % len(self.images)]
            imx = ui.Image.named(iname)
            self.archive("Showing image #%d %s" % (count, iname))
            self.imageView.image = imx
        self.mainView.close()

gui = GUI()
gui.run()

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions