Tarun Parswani
Tarun Parswani

Reputation: 21

How can I fix this Java heap stack error?

I have developed a barcode billing and inventory software using NetBeans 6.5. I don’t know why when the application runs for some time then some times it gives a Java heap stack (Out of Memory) error. I know there is some way to handle the memory allocation in NetBeans. How can I fix this?

Upvotes: 2

Views: 778

Answers (3)

InsertNickHere
InsertNickHere

Reputation: 3666

You should pass the argument -Xmx1024m when starting your program, so that the JVM can use more heap for your application. This -Xmx will give your program 1024 MB of RAM.

Upvotes: 1

Paul Jowett
Paul Jowett

Reputation: 6581

You need to figure out if your application needs a bigger working memory than the default setting, or if it is just leaking. If there is a memory leak (which is a common problem), then increasing the total memory will only give your application more time before it crashes. It's easy to do (as other posters have suggested) and it will show you if there is a bad leak, so try it first. If it keeps growing in memory, you need to look at what your application is holding onto in memory. Have a look at JConsole (which comes with Java6) or JHat or other tools.

Upvotes: 2

Zak
Zak

Reputation: 7078

Use java -Xmx<size>m to set the maximum size for the heap. And use a memory profiler like JMP(Java Memory Profiler) to figure out the memory consumption.

Similar questions on SO:

Upvotes: 1

Related Questions