开发者

Android 2D Game App freezing 1 Second Consistantly

I have a 2D game I am working on that has a minor almost unnoticeable issue. Every 1 second, exactly, it is doing a sort of mini hiccup effect. If you watch closely when objects are moving, they will pause, almost as if it were lagging.

I have spent the last 5 hours looking through my code, condensing repetitive data and ensuring that variables and what not are initialized correctly to prevent garbage collection, but I am a relatively new Android and Java programmer.

Either way, I am at a loss for what might be causing it, as I have blocked out portions of the code to see if any of it was causing the problem. On top of that, I added an FPS counter that displays constantly on screen which is staying above 60 FPS constantly.

Is there anything else that could cause this? It's not noticeable unless your looking closely.

It may be important to note in this log that the process ID's are not all the same. (Could another process be interfering?)

04-06 23:35:31.962: DEBUG/KeyguardViewMediator(1082): pokeWakelock(5000)

04-06 23:35:31.962: INFO/power(1082): *** set_screen_state 1

04-06 23:35:31.993: DEBUG/Sensors(1082): using sensors (name=sensors)

04-06 23:35:32.595: DEBUG/SurfaceFlinger(1082): Screen about to return, flinger = 0x120f38

04-06 23:35:33.016: DEBUG/KeyguardViewMediator(1082): pokeWakelock(5000)

04-0开发者_开发问答6 23:35:33.157: DEBUG/KeyguardViewMediator(1082): pokeWakelock(5000)

04-06 23:35:35.696: DEBUG/dalvikvm(4970): GC_EXTERNAL_ALLOC freed 971 objects / 39072 bytes in 50ms

04-06 23:35:36.743: DEBUG/dalvikvm(4970): GC_EXTERNAL_ALLOC freed 1350 objects / 53680 bytes in 38ms

04-06 23:35:37.774: DEBUG/dalvikvm(4970): GC_EXTERNAL_ALLOC freed 1431 objects / 57032 bytes in 37ms

04-06 23:35:38.813: DEBUG/dalvikvm(4970): GC_EXTERNAL_ALLOC freed 1445 objects / 57736 bytes in 37ms

04-06 23:35:39.876: DEBUG/dalvikvm(4970): GC_EXTERNAL_ALLOC freed 1457 objects / 58232 bytes in 38ms

04-06 23:35:40.923: DEBUG/dalvikvm(4970): GC_EXTERNAL_ALLOC freed 1458 objects / 58424 bytes in 37ms

04-06 23:35:41.977: DEBUG/dalvikvm(4970): GC_EXTERNAL_ALLOC freed 1451 objects / 58168 bytes in 37ms

04-06 23:35:43.016: DEBUG/dalvikvm(4970): GC_EXTERNAL_ALLOC freed 1446 objects / 58048 bytes in 38ms

04-06 23:35:44.157: DEBUG/dalvikvm(4970): GC_EXTERNAL_ALLOC freed 1490 objects / 59648 bytes in 46ms

04-06 23:35:45.032: DEBUG/dalvikvm(1813): GC_EXPLICIT freed 246 objects / 13640 bytes in 1042ms

04-06 23:35:45.282: DEBUG/dalvikvm(4970): GC_EXTERNAL_ALLOC freed 1522 objects / 60992 bytes in 37ms

04-06 23:35:46.313: DEBUG/dalvikvm(4970): GC_EXTERNAL_ALLOC freed 1456 objects / 58344 bytes in 37ms

04-06 23:35:47.376: DEBUG/dalvikvm(4970): GC_EXTERNAL_ALLOC freed 1452 objects / 58192 bytes in 37ms

04-06 23:35:48.454: DEBUG/dalvikvm(4970): GC_EXTERNAL_ALLOC freed 1484 objects / 59496 bytes in 37ms

04-06 23:35:49.509: DEBUG/dalvikvm(4970): GC_EXTERNAL_ALLOC freed 1440 objects / 57744 bytes in 45ms

04-06 23:35:49.696: DEBUG/dalvikvm(1836): GC_EXPLICIT freed 46 objects / 2208 bytes in 608ms

04-06 23:35:54.141: DEBUG/dalvikvm(4043): GC_EXPLICIT freed 91 objects / 7984 bytes in 56ms

04-06 23:35:59.180: DEBUG/dalvikvm(4051): GC_EXPLICIT freed 196 objects / 12176 bytes in 92ms

04-06 23:36:09.665: DEBUG/dalvikvm(4000): GC_EXPLICIT freed 37 objects / 2000 bytes in 65ms

04-06 23:36:14.790: DEBUG/dalvikvm(3976): GC_EXPLICIT freed 487 objects / 29960 bytes in 87ms


Try using TraceView to profile your application's performance. It's a great tool to detect how often some methods are called and how long they are taking. It helped me a great deal when I was having performance issues with my app.

I would also suggest looking into whether or not any of your non-UI classes are trying to access the UI class. Even a small delay would be noticeable in this case, and threadlock may be the issue you are experiencing.

Hope this helped!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜