1 Reply Latest reply on Feb 3, 2011 7:52 PM by mriem

    Converting JPEG to BufferedImage using previously allocated BufferedImage

      I have an application containing 11 Thumbnails fed by streams of JPEG images at 5 fps and a large panel that shows the image full size. Each thumbnail and the large panel are separate applets in a web page. The jpeg images are received directly into a byte array (byte[]) which is wrapped with a byte buffer. The images are then displayed using a jpeg reader which produces a new BufferedImage which is drawn using the awt graphics object drawImage method.

      The application works great except that the image io library always allocates a new BufferedImage for each conversion. This creates a huge swing in memory use and on some "busier" or less powerful clients, the mark and sweep garbage collection sometimes does not get run often enough to prevent memory use from getting rather huge, even if I call System.gc() on a regular basis. The overall effect is that the amount of JVM memory goes through some pretty big swings and after enough of these swings, the application starts to bog down. Note that there is no actual leak: the swings return to a memory allocation level that does not grow with time, and it always hits this level after the mark and sweep.

      To try to get this under control, I'd like to see if I can get a jpeg decoder that will write to an existing buffered image and its corresponding raster to avoid allocating a brand new RGB image for each frame. Is there any way to construct an image decoder for jpeg to awt renderable images that knows how to recycle existing BufferedImage/Raster objects?????