-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leaks in Image.close() after saving as pdf or png #6448
Comments
Could we have copies of the images? It would be helpful to remove as much ambiguity as possible from your example. You changed the title to "Memory leaks in PIL.PngImagePlugin.PngImageFile.close". So you believe that this problem can be replicated without saving as PDFs and without using your Pillow modification? |
If you're concerned about memory when saving PDFs, you might also be interested in this method that uses less memory. If that works, it would also remove the need for your Pillow modification. |
Unfortunately, i cannot send you the images in this issue publicly, because of copyright reason. Is there a way that i can send images privately ?
I assume that variable |
I have tried this before. In my case, converting thousand of images to PDF file in single run can cause slow performance. I have looked at Pillow module and found that https://github.com/python-pillow/Pillow/blob/9.2.0/src/PIL/PdfImagePlugin.py#L112 is causing slow, because the PDF plugin is trying to load the whole contents of PDF file. So modifying Pillow module is best option so far. |
I cannot send you the original images that i used for tests, but this should do. Source: https://commons.wikimedia.org/wiki/File:Lattinaichnusa.png |
After testing further with every extensions available ( Not affected
Failed
Affected
|
Really confident that the PR resolve the problem, thank you very much 👍 |
What did you do?
I'm converting 16 PNG images (with resolution 3000x4000) to PDF file and since Pillow didn't close the images after converting, it can cause huge memory. So i modified it's code from https://github.com/python-pillow/Pillow/blob/9.2.0/src/PIL/PdfImagePlugin.py#L218-L227, it looks like this
What did you expect to happen?
The memory stay low during converting
What actually happened?
Usually it worked for Pillow 9.0.1 and the memory stays between 20-60 MB. But after installing version 9.2.0, 9.1.0, and 9.1.1 it increased up to 700+ MB
Take a look at this footages
Pillow 9.0.1
Pillow_v9.0.1.mp4
Pillow 9.1.0
Pillow_v9.1.0.mp4
Pillow 9.1.1
Pillow_v9.1.1.mp4
Pillow 9.2.0
Pillow_v9.2.0.mp4
What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: