Question

I'm attempting to create a very large image in Java like so:

BufferedImage bi = new BufferedImage(58240, 1664, BufferedImage.TYPE_INT_RGB);

obviously the image is very large.

Now the issue I'm having is that it seems to work fine 100% on some computers but really slowly on others (and no this has NOTHING to do with specs).

My most major breakthrough came in Eclipse, the IDE refused to actually display the image and instead threw an error on one of the computers which displays the image really slowly (takes a considerable amount of time to resize the image and the like):

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Another interesting element of the error is that even on the computers it runs slowly on I can resize the window it's in until the paint function is no longer being called, then make it large again and if I do it 'right' it runs with 100% of speed.

Not sure what's going on at all, any ideas?

Was it helpful?

Solution

Your app is running out of memory - if I calculated it correctly, that image takes about 280MB.

Java programs have a maximum amount of memory they're allowed to use (heap space), which is fixed when the JVM is started, and how this limit is set varies between JVM implementation and versions. When you're running out of memory or close to the limit, the JVM will spend a lot of time doing garbage collection, which will slow it down considerably.

It may be that the only thing you have to do is to give the app more heap space; this is done with the -Xmx command line parameter.

OTHER TIPS

The issue is with the heap size of the Java Virtual Machine -- there just isn't enough on the systems that threw the OutOfMemoryError.

If the problem is occurring with systems running the Sun JVM, it is possible to change the heap size of the JVM by using Sun's JVM-specific options.

As of Sun's Java 6, the default values for the heap size is determined by the amount of system memory, but is also can be overridden by the -Xms option which changes the minimum heap size, and -Xmx that changes the maximum heap size. By default minimum heap size is 1/64 the amount of physical memory, and maximum is 1/4 the amount of physical memory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top