Bug 32354 - AWTRenderer fails with OutOfMemoryError when switching pages.
Summary: AWTRenderer fails with OutOfMemoryError when switching pages.
Status: CLOSED FIXED
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: awt renderer (show other bugs)
Version: 0.20.5
Hardware: All All
: P3 normal
Target Milestone: ---
Assignee: fop-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-23 10:15 UTC by Richard Zschech
Modified: 2012-04-01 06:57 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Zschech 2004-11-23 10:15:36 UTC
If you set a large scale factor say 400% on the AWTRenderer and render the first
page it works but when switching to the next page it fails with an OutOfMemoryError.
The problem is in the render(Page) method where it allocates a new BufferedImage
and graphics. During the BufferedImage allocation the the previous pageImage and
graphics can not be garbage collected because they are still referenced.
Therefor it requires enough memory for two BufferedImages.
This can be fixed by setting the pageImage and graphics variables to null before
allocating a new BufferedImage.
Also after the page has been rendered the graphics variable is not needed and
can be garbage collected.
Heres my proposed fix:

public void render(Page page) throws IOException {
    pageImage = null;
    // do work ...
    graphics = null;
}

I checked the current CVS to see if this has been addressed but it now generates
BufferedImages for each page and stores them in a bufferedImageList. This would
surely require a large amount of memory!
I personally prefer the Java2DHook style thing in the
http://nagoya.apache.org/wiki/apachewiki.cgi?FOPAvalonization/AltAPIProposalJM
where the user can supply the Graphics2D to render to so they can manage their
own memory.
Comment 1 Pascal Sancho 2007-11-20 01:59:09 UTC
Fixed in FOP 0.94 and probably earlier versions
Comment 2 Glenn Adams 2012-04-01 06:57:08 UTC
batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed