From 8f83e39970c7d7601f9ea697e2b25ce2831a2938 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Tue, 29 Aug 2023 15:33:03 +0200 Subject: [PATCH] Fix three memory leaks Add documentation to BaseFragment.initViews(View, Bundle) and BaseFragment.initListeners() --- .../java/org/schabi/newpipe/BaseFragment.java | 20 +++++++++++++++++++ .../newpipe/fragments/BaseStateFragment.java | 2 ++ .../newpipe/fragments/MainFragment.java | 6 ++++++ .../subscription/SubscriptionFragment.kt | 5 +++++ 4 files changed, 33 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/BaseFragment.java b/app/src/main/java/org/schabi/newpipe/BaseFragment.java index 19a99009b..5dde2a747 100644 --- a/app/src/main/java/org/schabi/newpipe/BaseFragment.java +++ b/app/src/main/java/org/schabi/newpipe/BaseFragment.java @@ -80,9 +80,29 @@ public abstract class BaseFragment extends Fragment { // Init //////////////////////////////////////////////////////////////////////////*/ + /** + * This method is called in {@link #onViewCreated(View, Bundle)} to initialize the views. + * + *

+ * {@link #initListeners()} is called after this method to initialize the corresponding + * listeners. + *

+ * @param rootView The inflated view for this fragment + * (provided by {@link #onViewCreated(View, Bundle)}) + * @param savedInstanceState The saved state of this fragment + * (provided by {@link #onViewCreated(View, Bundle)}) + */ protected void initViews(final View rootView, final Bundle savedInstanceState) { } + /** + * Initialize the listeners for this fragment. + * + *

+ * This method is called after {@link #initViews(View, Bundle)} + * in {@link #onViewCreated(View, Bundle)}. + *

+ */ protected void initListeners() { } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java index 85603d337..a3d3d8b60 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java @@ -80,6 +80,8 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC if (errorPanelHelper != null) { errorPanelHelper.dispose(); } + emptyStateView = null; + emptyStateMessageView = null; } protected void onRetryButtonClicked() { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java index e1b61ea7c..023642955 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -139,6 +139,12 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte } } + @Override + public void onDestroyView() { + super.onDestroyView(); + binding = null; + } + /*////////////////////////////////////////////////////////////////////////// // Menu //////////////////////////////////////////////////////////////////////////*/ diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index da1eba225..dda4326e9 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -115,6 +115,11 @@ class SubscriptionFragment : BaseStateFragment() { feedGroupsCarouselState = feedGroupsCarousel.onSaveInstanceState() } + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } + override fun onDestroy() { super.onDestroy() disposables.dispose()