summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard/android/fragment
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-07-25 02:48:02 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-07-25 02:59:26 +0200
commit559add3f714996e006dbff137ff4e7fd9dd0abcf (patch)
tree9dc9cf63e9e30ee04f35331474d800e19500e681 /app/src/main/java/com/wireguard/android/fragment
parentd615304e83d349b3da741d8262e4c998ea74ae52 (diff)
TunnelEditorFragment: plug memory leak on listeners
Apparently these don't get GC'd unless they're removed explicitly, because there's a global singleton registry of them. So, introduce a little registry of our own. Reported-by: Samuel Holland <samuel@sholland.org> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/fragment')
-rw-r--r--app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java14
1 files changed, 14 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java
index ce7c5570..1ab4f2a2 100644
--- a/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java
+++ b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java
@@ -36,6 +36,8 @@ import com.wireguard.config.Attribute;
import com.wireguard.config.Config;
import com.wireguard.config.Peer;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.Objects;
@@ -106,6 +108,7 @@ public class TunnelEditorFragment extends BaseFragment implements AppExclusionLi
}
};
+ private final Collection<Object> breakObjectOrientedLayeringHandlerReceivers = new ArrayList<>();
private final Observable.OnPropertyChangedCallback breakObjectOrientedLayeringHandler = new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(final Observable sender, final int propertyId) {
@@ -116,8 +119,11 @@ public class TunnelEditorFragment extends BaseFragment implements AppExclusionLi
return;
if (propertyId == BR.config) {
config.addOnPropertyChangedCallback(breakObjectOrientedLayeringHandler);
+ breakObjectOrientedLayeringHandlerReceivers.add(config);
config.getInterfaceSection().addOnPropertyChangedCallback(breakObjectOrientedLayeringHandler);
+ breakObjectOrientedLayeringHandlerReceivers.add(config.getInterfaceSection());
config.getPeers().addOnListChangedCallback(breakObjectListOrientedLayeringHandler);
+ breakObjectOrientedLayeringHandlerReceivers.add(config.getPeers());
} else if (propertyId == BR.dnses || propertyId == BR.peers)
;
else
@@ -136,13 +142,21 @@ public class TunnelEditorFragment extends BaseFragment implements AppExclusionLi
super.onCreateView(inflater, container, savedInstanceState);
binding = TunnelEditorFragmentBinding.inflate(inflater, container, false);
binding.addOnPropertyChangedCallback(breakObjectOrientedLayeringHandler);
+ breakObjectOrientedLayeringHandlerReceivers.add(binding);
binding.executePendingBindings();
return binding.getRoot();
}
+ @SuppressWarnings("unchecked")
@Override
public void onDestroyView() {
binding = null;
+ for (final Object o : breakObjectOrientedLayeringHandlerReceivers) {
+ if (o instanceof Observable)
+ ((Observable)o).removeOnPropertyChangedCallback(breakObjectOrientedLayeringHandler);
+ else if (o instanceof ObservableList)
+ ((ObservableList)o).removeOnListChangedCallback(breakObjectListOrientedLayeringHandler);
+ }
super.onDestroyView();
}