VD63
VD63

Reputation: 133

Heap space in android application

I have an application which uses a SurfaceView to draw an animation as fast as possible. It is almost perfect except that, from time to time, the animation freezes for a short period of time. This short time lasts approximately 10 ms, which it is not so much, but is large enough to be noticeable by the user.

I have seen that these freezes are caused by changes in the heap space, which are triggered by the garbage collector. Adding the android:largeHeap="true" in my application's manifest hasn't solved the problem.

Does anyone know how I could get rid of this annoying problem?

Upvotes: 1

Views: 111

Answers (2)

Jitsu
Jitsu

Reputation: 769

That's the garbage collector attempting to free up some resources. You would need to see logcat - it would be visible there.

I suggest optimizing memory usage (lower the bitmap sizes, or modify the loading scheme), or (if it's possible) find some interval at which nothing is intensively animated and do System.gc() at that point, to hide the freeze from the user.

Upvotes: 1

NIlesh Sharma
NIlesh Sharma

Reputation: 5665

It seems Android wasn't fast enough to grow the heap space for an app.

Try to use largeHeap setting in the Manifest file. With that setting on, Android leaves more free memory every time it grows the heap, which minimise the chance of hitting the current limit.

You just need to set largeHeap="true" on the application tag of your AndroidManifest.xml

Upvotes: 0

Related Questions