Java out of memory error - i am being careful but still get it! please help

I am trying to run my program and try to use as less as I can in terms of creating uneeded objects etc. But I get the

" java.lang.OutOfMemoryError: Java heap space" when I try to open a 9MB jpeg. I know that the file opens fine if i use only the module that opens and displays the file but for the overall program i run out of memory. I am pretty good on not declaring unused objects and opening the file is the first thing I do. Can someone help me out?

Thanks!

[482 byte] By [shaselaia] at [2007-11-27 6:45:46]
# 1

> I am trying to run my program and try to use as less

> as I can in terms of creating uneeded objects etc.

> But I get the

> " java.lang.OutOfMemoryError: Java heap space" when I

> try to open a 9MB jpeg. I know that the file opens

> fine if i use only the module that opens and displays

> the file but for the overall program i run out of

> memory. I am pretty good on not declaring unused

> objects and opening the file is the first thing I do.

> Can someone help me out?

> hanks!

1) increase the memory your jvm can use

2) check to see if you aren't opening it more than once

Aknibbsa at 2007-7-12 18:17:51 > top of Java-index,Java Essentials,Java Programming...
# 2
Is the jpeg 9MB compressed? You probably need to increase the heap size in that case. Use the vm argument -Xmx256M to intrease it to 256MB.Kaj
kajbja at 2007-7-12 18:17:51 > top of Java-index,Java Essentials,Java Programming...
# 3
where do i do that command? It didnt work with the command prompt. or java -Xmx256M ... thanks
shaselaia at 2007-7-12 18:17:51 > top of Java-index,Java Essentials,Java Programming...
# 4
> where do i do that command? It didnt work with the> command prompt. or java -Xmx256M ... thanksWhat do you mean "didn't work"? Be specific.java -cp some_class_path -Xmx256m MyClass
jverda at 2007-7-12 18:17:51 > top of Java-index,Java Essentials,Java Programming...
# 5

If you're still getting the OutOfMemoryError, then try making it even bigger.

Try opening a very small image that you know isn't compressed or that you know is small even uncompressed.

Use a debugger or print statements to see if you're opening the file multiple times and keeping multiple copies around.

You need to do some detective work.

jverda at 2007-7-12 18:17:51 > top of Java-index,Java Essentials,Java Programming...