Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

OutofMemory while reading JPEG file Using IMAGEIO

 
Mihir K Parekh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Rancher
Posts: 42970
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mihir K Parekh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!