Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My Android game has sudden lag spikes sometimes. I know this is due to something going wrong. My phone has a 1GHz processor so there shouldn't be a problem. Basically I use the Canvas class to render my entire game (I am about to learn OpenGL and don't know if this is the cause). I have a main game loop and about 4 threads. Why does it lag?

Thanks in advance.

share|improve this question
Sorry, thats what I meant. "Lag: Fall behind in movement, progress, or development; not keep pace with another or others." And why do i have such a lousy frame rate? – chrypthic Nov 17 '11 at 17:42
Could be canvas, but wait for someone who knows the Android platform better, to answer your question. GL. Also -- you may want to post your code. – Arcane Engineer Nov 17 '11 at 17:54
How do you know it's "due to something going wrong"? Perhaps your phone is doing other things that are slowing down your application like checking for updates or emails. – Richard Marskell - Drackir Nov 17 '11 at 20:37
-1, way too little detail here to give a reasonable answer. – Tetrad Nov 17 '11 at 20:38
GC potentially? They are usually really bad on mobile platforms; what how many objects you are creating - pool/re-use objects if necessary; I know this is a problem with C# on XBox+WP7 (which both have an inferior GC) - so this may very well apply to Java too. – Jonathan Dickinson Nov 17 '11 at 22:14
up vote 6 down vote accepted

This is most presumably the garbage collector kicking in.

There is no clean way to solve this problem unless you are willing to ditch Java for another language such as C++. See How can I avoid garbage collection delays in Java games? (Best Practices) for a few hints on how to mitigate the problem.

share|improve this answer
Yes there is, object pooling, as long as you're not using dynamic memory allocation in the game loop you can work around it. – Daniel Little Nov 17 '11 at 23:53
I don't think manually managing memory in c++ is a more clean way of solving this problem than.. manually managing the memory in Java , using object pools or plain hunting allocations down, moving them out loops, etc. – Tinco Nov 18 '11 at 3:09
@Tinco: well I think going to C++ has many other advantages including portability. – sam hocevar Nov 18 '11 at 10:21
Im gonna switch to OpenGL ES – chrypthic Nov 25 '11 at 19:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.