Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

out of memoey!! how to release a BufferedImage  RSS feed

 
chien-rong chen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
I successfully load a extremely large jpeg file, say 3000 x 2000, into BufferedImage.
When I try to load, same size, second jpeg file, out of memory message is shown.
Does anyone of you know how to release this BufferedImage so that I can load the second jpg file?
Or any other way to load the second jpg file?

Thanks,

chienrong chen
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
invoke flush() on your BufferedImage instance.
 
chien-rong chen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for replying.

I tried this way, but it doesn't work.

Can you explain more clearly? For example, where or when to put this method?

chienrong chen
 
Sudarshan Muramreddy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using the same buffer then you need to flush it out, just before you read the next one.

Regards,
Sudarshan
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't much to explain.

Since you are dealing with such large images it may help to make the initial memory pool larger by passing the argument -Xms to the virtual machine:

-Xmsn = Specify the initial size, in bytes, of the memory allocation pool. This value must be a multiple of 1024 greater than 1MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 2MB. Examples:
-Xms6291456
-Xms6144k
-Xms6m

from the SDK tool documentation. Keep in mind that this will not cure a memory leak, just hide it for a while. You can use Runtime.freeMemory() and Runtime.totalMemory() to monitor memory usage.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!