Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: java.lang.OutOfMemoryError: Java heap space

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java.lang.OutOfMemoryError: Java heap space

    Hi,
    I am new to this forum.

    I just finished making an image processing tool for my college project by manipulating the image pixels.
    Small size images up to 600-700 kb are loaded properly, but when when I try to load an image with size greater than 1 Mb it gives error.

    Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
    at GetImage.getImagePixels(GetImage.java:109)
    at GetImage.loadImage(GetImage.java:86)
    at First$2.actionPerformed(First.java:120)

    I tried increasing the heap size of jvm but still the same error.

    XX:MaxPermSize=128m
    -Xms128m
    -Xmx1024m

    Please help.
    Thanks


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: java.lang.OutOfMemoryError: Java heap space

    That is pretty expected, if you're doing things like storing millions of Objects based on each pixel of a large image. I'd look at modifying your algorithm to be as efficient as possible (this is one of the few cases I actually recommend bothering with optimization). Alternatively, you could also try saving stuff out to a file- but I'd try the optimization route first.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.OutOfMemoryError: Java heap space

    Thanks kevin for replying....I didnt get it though.What kind of optimization are you suggesting?.is there anything else you could suggest.
    I am using a 3D array for storing pixels and then manipulating those pixels to get the required effect.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: java.lang.OutOfMemoryError: Java heap space

    Without knowing your algorithm, I can't really tell you how to optimize it.

    The thing is, even with optimization, if you're storing all of the pixels (why a 3D array?), you're going to run out of memory with sufficiently large images. Perhaps you could work with the pixels one row at a time, or even one at a time, instead of storing them all at once?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: java.lang.OutOfMemoryError: Java heap space

    To add to Kevin's post, a single pixel for an 8 bit image can be stored in a single int primitive, (rgba - one byte for each value - access the values using bit operations), and all pixels for an image in a single 1D or 2D array. When one starts creating different ways to store these values that require larger data types/structures, you will more easily run into memory problems with larger image.

  6. #6
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.OutOfMemoryError: Java heap space

    Thanks alot kevin..

  7. #7
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.OutOfMemoryError: Java heap space

    Thanks alot copeg

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: java.lang.OutOfMemoryError: Java heap space

    No problem. Did you get it figured out?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Java Heap Space
    By aussiemcgr in forum Java Theory & Questions
    Replies: 4
    Last Post: September 8th, 2010, 05:05 PM
  2. AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
    By nasi in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 25th, 2010, 10:37 PM
  3. Replies: 15
    Last Post: February 28th, 2010, 10:30 PM
  4. Out of memory - Java heap space
    By fraxx in forum Java Theory & Questions
    Replies: 4
    Last Post: November 24th, 2009, 05:26 AM
  5. OutOfMemoryError (Java heap space)
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 21st, 2009, 11:56 AM