Giter Club home page Giter Club logo

Comments (14)

time007 avatar time007 commented on August 16, 2024 2

我试了试在onPause里调用pauseScroll就没有内存泄露了,onResume里start。轮播的线程占用了context,activity退出时主动停止就行。

from flycobanner_master.

happyHou avatar happyHou commented on August 16, 2024 2

这样子可以解决内存泄露,在onDetachedFromWindow()中结束线程

···
public class SimpleImageBanner extends BaseIndicaorBanner<Course, SimpleImageBanner> {

public SimpleImageBanner(Context context) {
    this(context, null, 0);
}

public SimpleImageBanner(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
}

public SimpleImageBanner(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
public void onTitleSlect(TextView tv, int position) {
}

@Override
public View onCreateItemView(int position) {
    Course data = list.get(position);
    ImageView imageView = new ImageView(context);
    int itemWidth = dm.widthPixels;
    int itemHeight = (int) (itemWidth * 430 * 1.0f / 1080);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

// imageView.setLayoutParams(new LinearLayoutCompat.LayoutParams(itemWidth,itemHeight));
imageView.setLayoutParams(new LinearLayout.LayoutParams(itemWidth,itemHeight));
Picasso.with(context).load(data.getImg_src()).into(imageView);
return imageView;
}

@Override
protected void onDetachedFromWindow() {
    pauseScroll();
    super.onDetachedFromWindow();
}

···

from flycobanner_master.

lucheng0522 avatar lucheng0522 commented on August 16, 2024 1

在onResume中应该使用goOnScroll()要不然报错

from flycobanner_master.

ysmintor avatar ysmintor commented on August 16, 2024

麻烦把问题说清楚!我也在用,描述出来才能修改!

from flycobanner_master.

time007 avatar time007 commented on August 16, 2024

确实有内存泄露,轮播的线程池应该持有当前界面的context

from flycobanner_master.

lucheng0522 avatar lucheng0522 commented on August 16, 2024

你们是如何解决的?我也碰到了内存泄漏问题

from flycobanner_master.

lucheng0522 avatar lucheng0522 commented on August 16, 2024

非常感谢你的回答,谢谢你。

from flycobanner_master.

time007 avatar time007 commented on August 16, 2024

哦,好的,我这暂时木有发现问题呢,哈哈,多谢你的提醒。

from flycobanner_master.

HappyJess avatar HappyJess commented on August 16, 2024

多谢大神们分析解决!

from flycobanner_master.

ysmintor avatar ysmintor commented on August 16, 2024

@happyHou

       在onDetachedFromWindo()里应该加一个是正在滑动的判断再pauseScroll()可能会好些吧?

from flycobanner_master.

lucheng0522 avatar lucheng0522 commented on August 16, 2024

但是你停止了,还需要再次启动。。
@OverRide
public void onResume() {
super.onResume();
convenientBanner.goOnScroll();
}

from flycobanner_master.

happyHou avatar happyHou commented on August 16, 2024

@ysmintor 没有必要。就是一个轮询线程。看看源码

from flycobanner_master.

happyHou avatar happyHou commented on August 16, 2024

@lucheng0522 对。普通的view你在activity或者fragmet中可以拿到它的引用,在合适的生命周期,开始滚动和停止滚动,是不会出现内存泄露的。但是有时候这个view必须在adapter中直接new出来,就不能通过activity的生命周期控制,只能用View的onDetachedFromWindow()的时候shutdwn这个线程。在我自己的项目中遇到这个问题了,经过实际测试,可以解决内存泄露。

from flycobanner_master.

feer921 avatar feer921 commented on August 16, 2024

我把作者的线程来定时轮播,改成直接使用Handler来处理了,参见:BaseBanner

from flycobanner_master.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.