Android ListView with SimpleAdapter leaking memory

This is a followup to my earlier question ( https://stackoverflow.com/questions/8174140/android-memory-leak ) after doing some research and following some of the steps suggested. My application has a UI loop in which a user clicks a ListView item, which draws another ListView after querying a web api. Clicking on an item will draw up another ListView. This process can be repeated many times by a user without finishing the activity. Here is a code snippet of how I am populating a ListView with SimpleAdapter.. //* Add available times value using array.length() List> datalist = new ArrayList>(); for (SomeResult result : results) { Map map = new HashMap(); map.put("field_a", result.field_a); map.put("field_b", result.field_b); datalist.add(map); } String[] from = {"field_a","field_b"}; int[] to = {R.id.textview_a,R.id.textview_b}; // get a reference to the ListView ListView lv = (ListView)findViewById(R.id.listview); lv.setBackgroundColor(0xffffffff); lv.setOnItemClickListener(itemclick_drawHours); SimpleAdapter adapter = new SimpleAdapter(this.getApplicationContext(), datalist, R.layout.list_item, from, to); lv.setAdapter(adapter); lv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); lv.setCacheColorHint(0xffffffff); viewFlipper.setDisplayedChild(2); Using DDMS and MAT, I noticed that while the number of ListView objects does not increase, the number of TextViews, RelativeLayouts and ImageViews were increasing steadily along with the number of times a user has clicked and a new list has been drawn. Here are the object counts of these three widgets +ListView at various stages of app usage. App Installed onto emulator: android.widget.TextView: 16 android.widget.RelativeLayout: 9 android.widget.ImageView: 8 android.widget.ListView: 4 Light Use (a dozen or so clicks and ListViews drawn): android.widget.TextView: 107 android.widget.RelativeLayout: 48 android.widget.ImageView: 34 android.widget.ListView: 4 Medium Use (a couple dozen clicks/ListViews drawn): // At this point, a lot of GC messages and Resizing JIT Table messages etc. in LogCat android.widget.TextView: 158 android.widget.RelativeLayout: 72 android.widget.ImageView: 61 android.widget.ListView: 4 Heavy Use (three dozen or so clicks/ListViews drawn): // Even more messages in logcat android.widget.TextView: 222 android.widget.RelativeLayout: 103 android.widget.ImageView: 92 android.widget.ListView: 4 The app does not actually crash while open, just gets less responsive and laggy. After a period of medium/heavy use, closing and opening the app causes an OutOfMemory Error when displaying an ImageView. Here is list_item.xml .. If you look at the 2(TextViews) to 1(ImageView) to 1(RelativeLayout) ratio in this template and in the object counts above, it seems that ImageViews, TextViews and RelativeLayouts created by SimpleAdapter are not being released properly. Is there anything obvious that I'm missing? I've read some other posts where they say this problem only seems to occur in "debug" mode. I'm not sure how to turn this on/off except changing the android:debuggable="true" or "false" in the manifest.

以上就是Android ListView with SimpleAdapter leaking memory的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏