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?
Asked
Active
Viewed 26 times
0
-
This depends on a your use case, you need to share your code to get a precise answer. – Jamal N Aug 17 '23 at 16:07
1 Answers
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