Android: GC_FOR_MALLOC caused by a long touch event?

I read and looked at touchEvents , mainly because my GC explodes when there is a long touch / slide event or many touch events . If I don’t touch the phone, it just stands idle as ~ 5 objects, as you can see from the first few GC_EXPLICIT that I executed from DDMS. Then I started to touch the screen and move around, and the objects rose around 13513 objects and actually called GC_FOR_MALLOC , which takes more than 100 ms. Here is my simple test code, and below is the dalvicvm tag log. If you have documentation on workarounds or reasons, or perhaps even another in-depth discussion of this issue, I would greatly appreciate it! Cheers and good luck in your own endeavors.

[the code]

  public class testClass extends Activity implements IOnSceneTouchListener{ int numberOfTouches = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); } @Override public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) { numberOfTouches++; return false; } } 

[LogCat]

 06-28 15:24:55.317: DEBUG/dalvikvm(2501): GC_EXPLICIT freed 5 objects / 128 bytes in 53ms 06-28 15:24:55.903: DEBUG/dalvikvm(2501): GC_EXPLICIT freed 5 objects / 136 bytes in 59ms 06-28 15:24:56.708: DEBUG/dalvikvm(2501): GC_EXPLICIT freed 5 objects / 128 bytes in 59ms 06-28 15:25:06.614: DEBUG/dalvikvm(2501): GC_EXPLICIT freed 6 objects / 168 bytes in 58ms 06-28 15:25:09.833: DEBUG/dalvikvm(2501): GC_EXPLICIT freed 7 objects / 192 bytes in 65ms 06-28 15:25:14.270: DEBUG/dalvikvm(2501): GC_EXPLICIT freed 8 objects / 232 bytes in 59ms 06-28 15:25:18.294: DEBUG/dalvikvm(2501): GC_EXPLICIT freed 6 objects / 160 bytes in 59ms 06-28 15:25:33.942: DEBUG/dalvikvm(1103): GC_FOR_MALLOC freed 13513 objects / 1403264 bytes in 121ms 06-28 15:26:53.684: DEBUG/dalvikvm(2139): GC_EXPLICIT freed 140 objects / 6960 bytes in 99ms 06-28 15:26:58.731: DEBUG/dalvikvm(1215): GC_EXPLICIT freed 668 objects / 71136 bytes in 117ms 06-28 15:27:31.637: DEBUG/dalvikvm(1103): GC_FOR_MALLOC freed 13962 objects / 1504296 bytes in 122ms 06-28 15:27:44.723: DEBUG/dalvikvm(2501): GC_EXPLICIT freed 63 objects / 2152 bytes in 59ms 06-28 15:27:46.676: DEBUG/dalvikvm(2501): GC_EXPLICIT freed 5 objects / 128 bytes in 65ms 06-28 15:27:47.238: DEBUG/dalvikvm(2501): GC_EXPLICIT freed 5 objects / 128 bytes in 58ms 

I haven't solved the problem yet, but stumbled upon this wonderful article on this exact issue: Problems with Android Touch

[edit] As stracka said, it is most likely due to flooding. My real problem, however, is with the distribution that is made for each event? Is there a way to reuse these events / objects to limit selection due to touch?

I am currently using andEngine , and touchEvents are merging, so there should be no more than ~ 5 ever allocated from scratch; otherwise they just reuse them?

Thanks for any ideas ....

+6
source share
2 answers

Are you using an older version of Android? I just read about the "touch event flood" issue on Android 1.5 at the Beginning of Android Games . The workaround for the author was to briefly switch the user interface stream to the onTouch () handler in order to limit the number of events received. I do not know how viable this decision is, or if it will be useful to you; the corresponding page from the book can be found here:

Starting Android Games, page 131

+3
source
  @Override public boolean onTouchEvent(MotionEvent event) { numberOfTouches++; //events can be handled as well. switch (event.getAction()) { case MotionEvent.ACTION_DOWN: invalidate(); break; case MotionEvent.ACTION_MOVE: invalidate(); break; case MotionEvent.ACTION_UP: invalidate(); break; } return true; } 

It lights up GC and mallocs. This is a view override method. Try and answer.

android.view.View.onTouchEvent (MotionEvent event)

Link:

http://developer.android.com/reference/android/view/View.html#onTouchEvent%28android.view.MotionEvent%29

0
source

Source: https://habr.com/ru/post/891587/


All Articles