Question

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.

Was it helpful?

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.

OTHER TIPS

Run it through a profiler. JProfiler is a good one to use.

Are you loading the picture with one shot? Why not tile it and make some threads that load the image? If the part of your program that loads the View is so big, why not just spread it in threads? Need more advice?

Good luck

First, 130Mb is lot, even for 2400x1800 image, this mean that you consume 27Byte per pixel.

For a classic 32 bit per pixel (or 4 byte) image, you would require only 16-17MB

Second from what you said, it seem that you consume more and more memory until the garbage collector is called and it do a lot of work to free up memory.

Your likely need to : - increase the maximum memory available - tweak the garbage collector to make smaller pauses but more often.

Edit : maybe you create lot of new image of this size instead of updating them, forcing lot of memory allocation and memory desalocation ?

There is very little to go on from the question, but a periodic slowdown in an application is often due to garbage collection. Run jvisualvm and look at the graphs relating to memory. If you see a saw-tooth pattern with the peaks coinciding with the start of the performance drop, then this points to your app slowing down due the garbage collector processing a large amount of objects. This could be dues to wasteful creation of objects in your code, or you may simply need to allocate more memory to the vm.

Here is a guide to

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top