我有以下Python代碼。問題在於內存使用量增長巨大。 鑑於Image.rotate()
返回一個新的對象,我會認爲舊的對象不能再有任何引用並被刪除。內存增長雖然被覆蓋了
問題
會發生什麼,我該如何解決這個問題?
代碼
from PIL import Image
src_im = Image.open("input.png")
steps = 120 # Works with 3
angle = 360.0/steps
rotation = src_im.convert('RGBA')
for _ in xrange(steps):
rotation = rotation.rotate(angle, expand = 1)
rotation = rotation.crop(rotation.getbbox()).resize(src_im.size)
rotation.save("out.png")
這是在Python 2.7.3。 Python 3特定的解決方案是可以接受的。
有趣。我剛剛嘗試過:gc.collect和explicit del,但沒有任何幫助。 – Jiri 2014-11-25 13:36:54