aspose file tools*
The moose likes Performance and the fly likes OutofMemory while reading JPEG file Using IMAGEIO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "OutofMemory while reading JPEG file Using IMAGEIO" Watch "OutofMemory while reading JPEG file Using IMAGEIO" New topic
Author

OutofMemory while reading JPEG file Using IMAGEIO

Mihir K Parekh
Greenhorn

Joined: Jul 20, 2012
Posts: 11

Hello All

I am reading an Jpeg file using following snippets



the file i try to read is 6480 and 4320 in dimension and just 2.34 MB in size. my heap size is 1024 MB.and i want to read file even larger in size say 25 - 30 mb and 10,000 * 12,000 in dimensions. then what all experts suggest me to accomplish my goal

getting following exception


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42282
    
  64
JPEG compresses images well. But in memory, a BufferedImage generally needs 4 bytes for each pixel just for the raw data, so that would be 6480 * 4320 * 4 = 112 MB, regardless of how big the file is.

With a 1024MB heap, that should still fit, though, unless there's tons of other stuff that can't be GC-ed. What's the command you use to start the JVM? Post all the options.

Have you tried allocating 2GB instead of 1GB?


Ping & DNS - my free Android networking tools app
Mihir K Parekh
Greenhorn

Joined: Jul 20, 2012
Posts: 11
Hello

thank you for your reply.i am using eclipse latest version. and i do understand your point of BufferedImage uncompressed size calculation. is there any other way to load big jpeg images into my application ? like BigDecimal in java is there any other option for large image file ?

Thank You
Mihir Parekh
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42282
    
  64
Try running your code outside of the IDE; who knows what that does to the memory settings. And then post here the command line arguments you used to start the JVM.
Mihir K Parekh
Greenhorn

Joined: Jul 20, 2012
Posts: 11
Hello

when i run my code out of ide it works fine.

my myeclipse.ini is

-startup
../Common/plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
--launcher.library
../Common/plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519
-install
C:/Program Files/Genuitec/MyEclipse-8.6
-vm
C:/Program Files/Genuitec/Common/binary/com.sun.java.jdk.win32.x86_1.6.0.013/jre/bin/client/jvm.dll
-configuration
configuration
-vmargs
-Xmx1024m
-XX:MaxPermSize=256m
-XX:ReservedCodeCacheSize=128m


so why can i run same code with no error outside of IDE ?

Thank You
Mihir Parekh
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42282
    
  64
Because of this:
Ulf Dittmer wrote:... who knows what that does to the memory settings.

IDEs are memory hogs; Eclipse probably needs 256MB or more just for itself.

For running the code in Eclipse; dig into the Eclipse settings to find out where you can set the JVM parameters for child processes - giving those 1 GB is unlikely to be the default, so as long as you don't change those values you'll run into trouble.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OutofMemory while reading JPEG file Using IMAGEIO