[messages] [Developers] Re: determining how much heap a BufferedImage uses

pgeerkens pgeerkens at hotmail.com
Wed Nov 10 09:56:03 MST 2010

I believe it is the heap manager causing the problem, not the buffered
image itself. I get the following output 
from the code below with min/max heap set to 961MB, totalling 896MB of
the 961MB available. When I bump the size factor in img3 to 0.2 I run
out of heap.
import java.awt.image.BufferedImage; 
public class BImageTest { 
  public static void main(String[] args) { 
    final int w = Integer.parseInt(args[0]); 
    final int h = Integer.parseInt(args[1]); 

    final BufferedImage img1 = 
       new BufferedImage(w*2, h*2, BufferedImage.TYPE_INT_ARGB); 
     System.out.println((4*w*2*h*2) >> 20); 
    final BufferedImage img2 = 
      new BufferedImage((int) (w*1.5), h, BufferedImage.TYPE_INT_ARGB); 
    System.out.println((int)((4*w*h*1.5)) >> 20); 

    final BufferedImage img3 = 
       new BufferedImage((int) (w*0.1), h, BufferedImage.TYPE_INT_ARGB);

     System.out.println((int)((4*w*h*0.1)) >> 20); 

Read this topic online here:

More information about the messages mailing list