Comments (14)
After some investigation it looks like dispose() needs to be called on
ImageReaders and ImageWriters after using them. The methods affected would be
net.coobird.thumbnailator.tasks.io.InputStreamImageSource.read()
net.coobird.thumbnailator.tasks.io.OutputStreamImageSink.write(BufferedImage)
net.coobird.thumbnailator.tasks.io.FileImageSource.read()
net.coobird.thumbnailator.tasks.io.FileImageSink.write(BufferedImage)
Original comment by [email protected]
on 16 May 2013 at 2:19
from thumbnailator.
Hi,
Thank you for taking your time to report this issue.
It does appear like there are many instances of people encountering
`OutOfMemoryError`s when using Thumbnailator with Java 7 Update 21.
The need to address this issue has been acknowledged.
Original comment by [email protected]
on 20 May 2013 at 1:47
- Changed state: Accepted
- Added labels: Priority-Critical
- Removed labels: Priority-Medium
from thumbnailator.
Issue 44 appears to be the same issue.
Original comment by [email protected]
on 20 May 2013 at 1:48
from thumbnailator.
I've also gotten a report of a memory leak via an e-mail from Vladimir Shomin
on April 24.
Quote:
> I have discovered some memory problem due exploiting system, when thousands of
> images have queued for thumbnailation - application server tomcat-7.0.39
> under jdk-1.7.0_21 crushes with OutOfMemoryError.
>
> Exploring heap state with VisualVM tool, I have found that memory is filled
> by megabyte-sized byte[] objects that linked as root by
> com.sun...JPEGImageReader . Forums recommend to use BufferedImage.dispose()
> and ImageReader.flush() methods beyond image processing cause its releases
> low-level resources used within image manipulations.
Again, this appears to occur when using Java 7 Update 21, which is the most
up-to-date version of Java available as of the time of writing this comment.
Therefore, this issue should be given the highest priority.
Original comment by [email protected]
on 20 May 2013 at 1:59
from thumbnailator.
Issue 44 has been merged into this issue.
Original comment by [email protected]
on 20 May 2013 at 2:22
from thumbnailator.
Reproducing the Problem
-------------------------
In an effort to reproduce the problem, I ran a variation of the following code:
Thumbnails.of(new File("/path/to/images").listFiles()
.scale(0.1)
.toFiles(new ConsecutivelyNumberedFilenames(new File("/path/for/thumbnails")));
I set the JVM's maximum heap settings to `-Xmx96m`, as that was the easiest
value to see the Java 1.7.0_21 JVM to throw an `OutOfMemoryError` while
processing images.
Using Thumbnailator 0.4.3 with the above settings, Java 1.7.0_21 would throw an
`OutOfMemoryError` after processing 15 JPEGs which had the dimensions of 3648 x
2736 pixels.
In contrast, when running with the same settings on Java 1.7.0_4, an
`OutOfMemoryError` did not occur.
Attempting a Fix
-------------------------
As pointed out by the issue reporters, the problem probably lies in the lack of
disposal code for the `ImageReader`s and `ImageWriter`s.
First, the disposal of the `ImageReader`s in the `FileImageSource` and
`InputStreamImageSource` classes were added.
However, after running the test code, it encountered an `OutOfMemoryError` at
15 images; the same as last time.
Next, the disposal of the `ImageWriters`s in the `FileImageSink` and
`InputStreamImageSink` classes were added.
The results this time was that the test code would run without encountered an
`OutOfMemoryError`.
(The code was subsequently changed to output to PNG, and the results were the
same -- no `OutOfMemoryError`.)
As an added measure, a call to `BufferedImage.flush` has been added to the
`Thumbnailator.createThumbnail(ThumbnailTask<?, ?>)` method, which should free
up some resources as well.
Current Status
-------------------------
Thumbnailator 0.4.4 which addresses this `OutOfMemoryError` issue should be
ready (hopefully) by the end of the week.
The changes has been pushed to the repository under the `0.4.4` branch:
http://code.google.com/p/thumbnailator/source/browse/?name=0.4.4
All unit tests are passing at this point, but I'll perform some manual testing
before release.
Original comment by [email protected]
on 21 May 2013 at 4:16
- Changed title: OutOfMemoryErrors (memory leak) when using latest version of Java 7
- Changed state: Started
- Added labels: Milestone-0.4.4
from thumbnailator.
Issue 46 is similar issue (though that may not mean the cause is similar).
Please take a look as well.
Original comment by [email protected]
on 22 May 2013 at 3:33
from thumbnailator.
Issue 46 is for jdk 1.6 build 45.
Original comment by [email protected]
on 22 May 2013 at 3:34
from thumbnailator.
I have reproduced the problem with Thumbnailator 0.4.3 running on Java 6 Update
45.
When running the candidate for Thumbnailator 0.4.4 on Java 6 Update 45, it does
not exhibit the `OutOfMemoryError` problem.
I'll merge Issue 46 into this issue.
Original comment by [email protected]
on 23 May 2013 at 12:23
- Changed title: OutOfMemoryErrors (memory leak) when using latest versions of Java 6 and 7
from thumbnailator.
Issue 46 has been merged into this issue.
Original comment by [email protected]
on 23 May 2013 at 12:25
from thumbnailator.
Issue 45 has been merged into this issue.
Original comment by [email protected]
on 23 May 2013 at 2:45
from thumbnailator.
This issue has been resolved in Thumbnailator 0.4.4.
I'd like to thank everyone involved in resolving this issue for contributing
your time and effort! :)
Original comment by [email protected]
on 23 May 2013 at 3:49
- Changed state: Fixed
from thumbnailator.
was this a bug in a particular jdk version? was there a commit that fixed it?
just wondering
Original comment by rogerpack2005
on 7 Jan 2015 at 12:19
from thumbnailator.
No bug in the jdk, just a bug in Thumbnailator where resources weren't being
cleaned up. It only seemed to matter in more recent jdk versions which were
doing some optimizations by re-using resources (assuming they'd be disposed of
when necessary)
Original comment by [email protected]
on 7 Jan 2015 at 12:39
from thumbnailator.
Related Issues (20)
- Jigsaw modules support HOT 5
- No suitable ImageReader found for source data(jpeg Picture format) HOT 2
- How to ensure the GIF dynamic effect after compression HOT 1
- Do you have plans to support WebP, AVIF? HOT 1
- Thumbnail not properly generating from PNG images HOT 2
- Image color loss during conversion HOT 3
- Define an Automatic-Module-Name HOT 1
- the image format webp is not support HOT 5
- No suitable ImageReader found for source data errors HOT 1
- After resize the image is rotated HOT 3
- 300dpi tiff image changed to 96pi jpg but pixel does not chage HOT 1
- Incorrect cropping when specifying sourceRegion and an image that has exif orientation HOT 2
- Multi-threaded processing of images with large pixel width and height leads to memory OutOfMemoryError
- the .pict file is not supported HOT 1
- javax.imageio.IIOException: Invalid JPEG file structure: two SOF markers HOT 1
- Add crop method usage to examples HOT 2
- How to make the image width fixed when the image is scaled HOT 1
- Does the thumbnailator support generating thumbnails for png images? HOT 1
- Conversion error caused by image reading failure
- Native image service unable to compress image
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thumbnailator.