GithubHelp home page GithubHelp logo

Memory leak when opening images about pillow HOT 4 OPEN

aIligat0r avatar aIligat0r commented on June 5, 2024
Memory leak when opening images

from pillow.

Comments (4)

Yay295 avatar Yay295 commented on June 5, 2024 1

It looks like it thinks the errors might be coming from lines 192 and 700?

def call(self, cid, pos, length):
"""Call the appropriate chunk handler"""
logger.debug("STREAM %r %s %s", cid, pos, length)
return getattr(self, "chunk_" + cid.decode("ascii"))(pos, length)

class PngImageFile(ImageFile.ImageFile):
format = "PNG"
format_description = "Portable network graphics"

from pillow.

radarhere avatar radarhere commented on June 5, 2024

If I increase the number of loops to 1000, I find that the memory drops down again at a certain point. Since it is not continuously increasing, I don't think it is a leak.

You might like to read #7935, in particular #7935 (comment)

Pillow's memory allocator doesn't necessarily release the memory in the pool back as soon as an image is destroyed, as it uses that memory pool for future allocations. See Storage.c (https://github.com/python-pillow/Pillow/blob/main/src/libImaging/Storage.c#L310) for the implementation.

from pillow.

Yay295 avatar Yay295 commented on June 5, 2024

If I increase the number of loops to 1000, I find that the memory drops down again at a certain point.

It would probably be good to add gc.collect() (import gc) to the end of each loop. It might just not be running that often.

from pillow.

radarhere avatar radarhere commented on June 5, 2024

It would probably be good to add gc.collect() (import gc) to the end of each loop. It might just not be running that often.

I added gc.collect() in, but it doesn't make an obvious difference.

It looks like it thinks the errors might be coming from lines 192 and 700?

I see line 1083 on my machine. This would be easier to discuss if the original image could be uploaded here.

I have previously encountered an error in Webp formats. The leak was in the WebPImagePlugin plugin. I solved this by changing the value of the variable HAVE_WEBPANIM (PIL._webp.HAVE_WEBPANIM) to False.

If I test a WebP image with your above code, I again find that the memory drops down again at a certain point.

from pillow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.