关于遇到的内存泄漏整理

来源:互联网 发布:mysql 服务器配置 编辑:程序博客网 时间:2024/06/05 20:11

问题1:

在做viewPager 无限循环时候出现的内存泄漏问题 导致多次循环后崩溃

进行多次后开始显示

Skipped 31 frames!  The application may be doing too much work on its main thread.

主线程做了太多的事情导致线程阻塞了, 


原因是adapter 里面 , 不能每次都inflate 一个布局, 也需要做重用机制

int realPosition = position%list.size();        View view = findViewByPosition(container,realPosition);

    private View findViewByPosition(ViewGroup container,int position){        for (View view : mViews) {            if (((int)view.getTag()) == position&&view.getParent()==null){                return view;            }        }        View view = LayoutInflater.from(container.getContext()).inflate(R.layout.group_list_item,null,false);        view.setTag(position);        mViews.add(view);        return view;    }