diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 9081020ebf..fc5917eb40 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -1036,6 +1036,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. @Override public boolean onLongClick(View view) { DB.shrinkMemory(view.getContext()); + new ViewModelProvider(getActivity()).get(ViewModelMessages.class).cleanup(); view.postDelayed(new Runnable() { @Override public void run() { diff --git a/app/src/main/java/eu/faircode/email/ViewModelMessages.java b/app/src/main/java/eu/faircode/email/ViewModelMessages.java index 9f7db5a143..aabbdba958 100644 --- a/app/src/main/java/eu/faircode/email/ViewModelMessages.java +++ b/app/src/main/java/eu/faircode/email/ViewModelMessages.java @@ -475,6 +475,16 @@ public class ViewModelMessages extends ViewModel { }.execute(context, owner, new Bundle(), "model:ids"); } + void cleanup() { + dump(); + for (AdapterMessage.ViewType viewType : new ArrayList<>(models.keySet())) { + if (viewType != last && !models.get(viewType).list.hasObservers()) { + Log.i("Cleanup model viewType=" + viewType); + models.remove(viewType); + } + } + } + private class Args { private long account; private String type;