mosaic memory allocation problem
I've researched for some time now, and cannot find the solution to my problem. I'm trying to render a collection of tiles on the screen, where each tile is stored as a 500x500 pixel JPEG on disk. Here are my methods:
- loop through tiles on disk and call JAI.create("fileload",fileName) to load each one
and then JAI.create("translate",pb, null) to indicate where in the huge image this tile is located.
- set the sources to be all of the tiles and call JAI.create("mosaic", pb) to create the entire image.
- each time a user scales, perform JAI.create("scale",pb) on the mosaic
- draw the new image on the graphics object to display to the user. This is done by grabbing the visible tiles, and drawing them using their BufferedImage representation.
My problem ends up being on the draw. Any time I try to draw, the memory allocation shoots up from 15Mb to 80Mb. I know I could just up the memory size, but something here doesn't sit right. Since JAI is supposed to only load what is visible, then the memory shouldn't shoot up that much. When I was doing file loading manually without JAI, that is, loading tiles that were visible from disk and drawing them, it never went up that much. Even when I try to do a crop operation on a rectangular bound, it shoots up to over 80Mb. I've also tried to flip the scaling and mosaic operations to no avail (although it performs better) . What can I do differently that might improve the memory consumption?
A separate issue was when the user would zoom out causing a lot of tiles to be displayed. This would cause the zooming to slow tremendously. I think it is due to the fact that JAI has to load all of the different tiles when the drawing occurs. Any performance enhancements I can make?
Thanks for the help!