Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当ConvenientBanner作为listview等子view,postDelayed内存泄漏 #77

Closed
xiaolongyuan opened this issue Dec 30, 2015 · 8 comments · Fixed by #81
Closed

当ConvenientBanner作为listview等子view,postDelayed内存泄漏 #77

xiaolongyuan opened this issue Dec 30, 2015 · 8 comments · Fixed by #81

Comments

@xiaolongyuan
Copy link
Contributor

No description provided.

@xiaolongyuan
Copy link
Contributor Author

image

@xiaolongyuan
Copy link
Contributor Author

ConvenientBanner 可以省略掉这个Handler吧?
private Handler timeHandler = new Handler();

postDelayed

removeCallbacks

View都有相应方法的

@xiaolongyuan
Copy link
Contributor Author

貌似找到原因 当ConvenientBanner 作为RecyclerView 或者ListView 的子项时 RecyclerView 会回收布局 以供重用,此时

 localImages.add(R.mipmap.home_banner);
        localImages.add(R.mipmap.home_banner_2);

        //本地图片例子
        convenientBanner.setPages(
                new CBViewHolderCreator<LocalImageHolderView>() {
                    @Override
                    public LocalImageHolderView createHolder() {
                        return new LocalImageHolderView();
                    }
                }, localImages)
                //设置两个点图片作为翻页指示器,不设置则没有指示器,可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设
                .setPageIndicator(new int[]{R.mipmap.ic_page_indicator, R.mipmap.ic_page_indicator_focused})
                        //设置指示器的方向
                .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.ALIGN_PARENT_LEFT)
//                .setOnPageChangeListener(this)//监听翻页事件
                .setOnItemClickListener(this)
                .startTurning(AUTO_TURNING_TIME);

会重复调用 - -

@imliujun
Copy link

这里重复调用是你的写法问题吧?你在外部给convenientBanner初始化一次,设置为RecyclerView的head,以后都是使用这一个View,为什么要重复调用呢?

@xiaolongyuan
Copy link
Contributor Author

是的 我是用的是这个库 https://github.com/mrmans0n/smart-adapters
我正在尝试 覆盖RecyclerView.Adapter 的 setHasStableIds 和 getItemId 方法 去解决问题
mrmans0n/smart-adapters#18

@imliujun
Copy link

@xiaolongyuan
Copy link
Contributor Author

smart-adapters 支持 RecyclerView 、 ListView 添加个扩展还是挺方便的

@xiaolongyuan
Copy link
Contributor Author

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        BindableViewHolder bindableViewHolder = (BindableViewHolder) holder;
        bindableViewHolder.setViewEventListener(viewEventListener);
        Object item = listItems.get(position);
        if (item != null) {
            bindableViewHolder.bind(item, position);
        }
    }

这里的代码太暴力 .......................
接着改

@xiaolongyuan xiaolongyuan changed the title 内存溢出问题。 当ConvenientBanner作为listview等子view,postDelayed内存泄漏 Jan 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants