Search code examples
javaimagememorylagbuffered

Java app breaks 10% of the time


I have an app that uses a 2400x1800 buffered Image (which I know it takes a lot of resources), but it works perfectly more than 90% of the time. Takes 130 mb of RAM and uses 5% of CPU.

The problem is that, 10% of the time, it has a big lag and consumes only 40 to 50 mb RAM and uses 50% of CPU. Why didn't it eat the same memory?

I know I should post some code, but the app is really big, a link to something that might talk a bit about this particular issue would be of great help.


Solution

  • Maybe running the JVM parameters like Xmx(this is the max size avaliable to a application to use) and Xss( this is the starting memory for that application ) could help you.

    try this in your eclipse ( assuming you use it )

    go to RUN menu,

    then Run configurations...

    then select your runner.

    and click on the (x)=Arguments tab.

    add this to your VM arguments

    -Xmx512m -Xss150m

    Try running it... this will make your JVM start with at least 150mb of free RAM already allocated to it...

    If not using eclipse just add those params to your java command line.