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

关于内存泄漏 #50

Closed
Gundam0079 opened this issue Sep 8, 2017 · 1 comment
Closed

关于内存泄漏 #50

Gundam0079 opened this issue Sep 8, 2017 · 1 comment

Comments

@Gundam0079
Copy link

举一个例子
listener是匿名内部类会持有UI层比如fragment的引用
如果网络比较慢listener异步请求 又销毁了fragment就会有泄露的风险
共同学习 现在已知的解决方法就是利用弱引用 加静态匿名内部类的方法避免
public void showBanncerPage(final RequestImpl listener) {
Subscription subscription = HttpUtils.getInstance().getDongTingServer().getFrontpage()
.observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io())
.subscribe(new Observer() {
@OverRide
public void onCompleted() {
}

                @Override
                public void onError(Throwable e) {
                    listener.loadFailed();
                }

                @Override
                public void onNext(FrontpageBean frontpageBean) {
                    listener.loadSuccess(frontpageBean);
                }
            });
    listener.addSubscription(subscription);
}
@youlookwhat
Copy link
Owner

嗯恩 没有很严谨,我再完善一下,那个页面在首页里,退出的话就退出App了,不过有其他子页面用到就内存泄漏了。非常感谢提出!

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

No branches or pull requests

2 participants