Commit 0d252ef3 authored by Tiago Cunha's avatar Tiago Cunha

Fix a memory leak

parent 18170308
...@@ -17,6 +17,7 @@ import chat.rocket.android.helper.TextUtils; ...@@ -17,6 +17,7 @@ import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.model.ServerConfig; import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.realm_helper.RealmObjectObserver; import chat.rocket.android.realm_helper.RealmObjectObserver;
import chat.rocket.android.realm_helper.RealmStore; import chat.rocket.android.realm_helper.RealmStore;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers; import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers; import rx.schedulers.Schedulers;
...@@ -29,6 +30,8 @@ public class InputHostnameFragment extends AbstractServerConfigFragment { ...@@ -29,6 +30,8 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
realm.where(ServerConfig.class).equalTo(ServerConfig.ID, serverConfigId)) realm.where(ServerConfig.class).equalTo(ServerConfig.ID, serverConfigId))
.setOnUpdateListener(this::onRenderServerConfig); .setOnUpdateListener(this::onRenderServerConfig);
Subscription serverPolicySubscription;
public InputHostnameFragment() { public InputHostnameFragment() {
} }
...@@ -60,7 +63,11 @@ public class InputHostnameFragment extends AbstractServerConfigFragment { ...@@ -60,7 +63,11 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
final ServerPolicyApiValidationHelper validationHelper = final ServerPolicyApiValidationHelper validationHelper =
new ServerPolicyApiValidationHelper(serverPolicyApi); new ServerPolicyApiValidationHelper(serverPolicyApi);
ServerPolicyHelper.isApiVersionValid(validationHelper) if (serverPolicySubscription != null) {
serverPolicySubscription.unsubscribe();
}
serverPolicySubscription = ServerPolicyHelper.isApiVersionValid(validationHelper)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
...@@ -79,6 +86,9 @@ public class InputHostnameFragment extends AbstractServerConfigFragment { ...@@ -79,6 +86,9 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
@Override @Override
public void onDestroyView() { public void onDestroyView() {
serverConfigObserver.unsub(); serverConfigObserver.unsub();
if (serverPolicySubscription != null) {
serverPolicySubscription.unsubscribe();
}
super.onDestroyView(); super.onDestroyView();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment