0

I use tasks in viewModel and want to remove listeners in onCleared but there is no method to do that, is it needed or not? I have found onCompleteListener with activity paramenter that in result clears listener in onStop but i'd like to leave authentication logic in VM.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Mark D
  • 95
  • 2
  • 8

1 Answers1

0

It is not needed. It should be garbage collected after the Task itself completes and becomes garbage collected.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • What about temporary leaks? if there's a long fetching process and user navigates to another activity/fragment there would be a strong reference from listener to outer class(VM) – Mark D Sep 27 '19 at 10:37
  • If that's how you implemented the listener, yes. You will have to handle that case correctly on your own (by not using inner classes whose outer class is long-lived). – Doug Stevenson Sep 27 '19 at 10:42