0

I figured that since both LiveData & Flow should be lifecycle aware that there is no reason to do this. Is there any benefit or detriment to setting them to null yourself in onCleared?

user1743524
  • 655
  • 1
  • 7
  • 14

1 Answers1

1

Since both LiveData and Flow are lifecycle-aware they will automatically clean up their resources in the ViewModel's onCleared() method. So there's no need to explicitly set them to null.

Sarah
  • 175
  • 4
  • would there ever be a reason to create the livedata in a fragment/activity? When is a flow preferable to LiveData? – user1743524 Aug 19 '23 at 20:49