So, I've written a Java-based WebQuerySave Agent to resize uploaded JPEGs photos attached to a document. Users can upload any size of file and the code reduces them all to a maximum of 450px wide.
The code is working but there are intermittent memory issues, like below:
28/12/2011 13:24:24 HTTP JVM: java.lang.OutOfMemoryError
When this hits, the Java agent fails to complete (obviously, I guess) and the photo is not resized. Ouch.
Before I pass blame to the server I need to make sure my code isn't to blame. I have a suspicion it's because I'm not clearing up after myself properly.
In order to perform the image resize the code uses objects based on the following classes:
Which of these need recycling? Which need flushing? Which need closing? I find it all a bit confusing and I'm not sure how you even are meant to know or work this out.
Is it good practice just to call .recycle() on everything? And .flush() or .close() on any class which supports those methods?