#1684 ✓resolved
Nedyalko Zhekov

Images.resize, Images.crop: java.lang.OutOfMemoryError:GC overhead limit exceeded

Reported by Nedyalko Zhekov | July 18th, 2013 @ 01:31 PM | in 1.3 (closed)

I'm working currently on a small web project where the user can upload some images. The project is based on play framework 1.2.5. Every image must be cropped and resized. For this purpose I use play.libs.Images.crop and play.libs.Images.resize. When the user uploads continuously images the framework throws "OutOfMemoryError:GC overhead limit exceeded". After this message the user is unable to upload images anymore because on any other request the very same exception is thrown. I read some of the code used in the methods play.libs.Images.crop and play.libs.Images.resize and saw that in both methods the writer that finally writes the image on the disk is not closed. I've copied the methods in a new class and tested the very same code but with this line added. With this code modification the exception was not observed anymore.

ImageWriteParam params = writer.getDefaultWriteParam();  
writer.setOutput(new FileImageOutputStream(to));  
IIOImage image = new IIOImage(dest, null, null);  
writer.write(null, image, params);  
riter.dispose(); // <--- NEW LINE  
IIOImage image = new IIOImage(dest, null, null);  
writer.write(null, image, params);  
writer.dispose(); // <--- NEW LINE  
Ubuntu 12.04  
$ uname -a
Linux XXXXXX 3.2.0-49-generic \#75-Ubuntu SMP Tue Jun 18 17:39:32 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

$ java -version
java version "1.6.0_27"  
OpenJDK Runtime Environment (IcedTea6 1.12.5) (6b27-1.12.5-0ubuntu0.12.04.1)  
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
Execution exception (In /app/controllers/admin/Images.java around line 174)  
OutOfMemoryError occured : GC overhead limit exceeded

play.exceptions.JavaExecutionException: GC overhead limit exceeded  
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:237)
    at Invocation.HTTP Request(Play!)
Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded  
    at java.awt.image.SinglePixelPackedSampleModel.getPixels(SinglePixelPackedSampleModel.java:486)
    at java.awt.image.Raster.getPixels(Raster.java:1583)
    at java.awt.image.WritableRaster.setRect(WritableRaster.java:464)
    at sun.awt.image.ByteInterleavedRaster.setRect(ByteInterleavedRaster.java:1149)
    at java.awt.image.WritableRaster.setRect(WritableRaster.java:403)
    at com.sun.imageio.plugins.jpeg.JPEGImageWriter.grabPixels(JPEGImageWriter.java:1790)
    at com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeImage(Native Method)
    at com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeOnThread(JPEGImageWriter.java:1058)
    at com.sun.imageio.plugins.jpeg.JPEGImageWriter.write(JPEGImageWriter.java:360)
    at play.libs.Images.crop(Images.java:154)
    at controllers.admin.Images.addDimension(Images.java:174)
    at controllers.admin.Images.saveImage(Images.java:36)
    at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:557)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:508)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:484)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:479)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
    ... 1 more

It would be cool if you can integrate this small fix in any future 1.2.x release.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2>Play framework</h2>

Play makes it easier to build Web applications with Java. It is a clean alternative to bloated Enterprise Java stacks. It focuses on developer productivity and targets RESTful architectures. Learn more on the <a href="http://www.playframework.org">http://www.playframework.org</a> website.<br><br>

<h2>Source code is hosted on github</h2>Check out our repository at <a href="http://github.com/playframework/play">http://github.com/playframework/play</a><br><br>

<h2>Contributing, creating a patch</h2> Please read the <a href="http://play.lighthouseapp.com/projects/57987/contributor-guide">contributor guide</a><br><br>

<h2>Reporting Security Vulnerabilities</h2> Since all bug reports are public, please report any security vulnerability directly to <em>guillaume dot bort at gmail dot com</em>.<br><br>

<h2>Creating a bug report</h2> Bug reports are incredibly helpful, so take time to report bugs and request features in our ticket tracker. We’re always grateful for patches to Play’s code. Indeed, bug reports with attached patches will get fixed far quickly than those without any.<br><br>

Please include as much relevant information as possible including the exact framework version you're using and a code snippet that reproduces the problem.<br><br>

Don't have too much expectations. Unless the bug is really a serious "everything is broken" thing, you're creating a ticket to start a discussion. Having a patch (or a branch on Github we can pull from) is better, but then again we'll only pull high quality branches that make sense to be in the core of Play.