From 23c9caf87e9eed1e2b5c5367aec7ff0807e8a97a Mon Sep 17 00:00:00 2001 From: inorichi Date: Wed, 9 Dec 2015 15:22:06 +0100 Subject: [PATCH] Fix memory leak in reader --- .../kanade/mangafeed/ui/reader/ReaderActivity.java | 6 ++++-- .../eu/kanade/mangafeed/ui/reader/ReaderMenu.java | 13 +++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java index 123daa1de0..6670774bf9 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java @@ -51,7 +51,7 @@ public class ReaderActivity extends BaseRxActivity { private ReaderMenu readerMenu; private int uiFlags; - private CompositeSubscription subscriptions; + protected CompositeSubscription subscriptions; private Subscription customBrightnessSubscription; private static final int LEFT_TO_RIGHT = 1; @@ -96,7 +96,7 @@ public class ReaderActivity extends BaseRxActivity { @Override protected void onDestroy() { - readerMenu.destroy(); + subscriptions.unsubscribe(); if (viewer != null) viewer.destroy(); super.onDestroy(); @@ -114,6 +114,8 @@ public class ReaderActivity extends BaseRxActivity { } public void onChapterReady(List pages, Manga manga, Chapter chapter) { + if (viewer != null) + viewer.destroy(); viewer = createViewer(manga); viewer.onPageListReady(pages); viewer.updatePageNumber(); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderMenu.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderMenu.java index fdf2174541..da5bd6762f 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderMenu.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderMenu.java @@ -27,7 +27,7 @@ import eu.kanade.mangafeed.data.database.models.Chapter; import eu.kanade.mangafeed.data.database.models.Manga; import eu.kanade.mangafeed.data.preference.PreferencesHelper; import icepick.State; -import rx.subscriptions.CompositeSubscription; +import rx.Subscription; public class ReaderMenu { @@ -51,8 +51,6 @@ public class ReaderMenu { private DecimalFormat decimalFormat; - private CompositeSubscription subscriptions; - public ReaderMenu(ReaderActivity activity) { this.activity = activity; this.preferences = activity.getPreferences(); @@ -64,12 +62,11 @@ public class ReaderMenu { seekBar.setOnSeekBarChangeListener(new PageSeekBarChangeListener()); decimalFormat = new DecimalFormat("#.##"); - subscriptions = new CompositeSubscription(); initializeOptions(); } - public void destroy() { - subscriptions.unsubscribe(); + public void add(Subscription subscription) { + activity.subscriptions.add(subscription); } public void toggle() { @@ -126,7 +123,7 @@ public class ReaderMenu { private void initializeOptions() { // Orientation changes - subscriptions.add(preferences.lockOrientation().asObservable() + add(preferences.lockOrientation().asObservable() .subscribe(locked -> { int resourceId = !locked ? R.drawable.ic_screen_rotation : activity.getResources().getConfiguration().orientation == 1 ? @@ -240,7 +237,7 @@ public class ReaderMenu { } private void initializePopupMenu() { - subscriptions.add(preferences.customBrightness() + add(preferences.customBrightness() .asObservable() .subscribe(isEnabled -> { customBrightness.setChecked(isEnabled);