1

I'm using MVVM in an Android project. The usual flow for my operations and data looks like this (just like it should in MVVM).

View -> ViewModel -> Repository -> Data Source        [Operation Flow] 
View <- ViewModel <- Repository <- Data Source        [Data Flow]

The Data Source has custom Observable fields that hold state for a particular data entity. I'm interested in my Repository subscribing to the Obervables in Data Source. But since Repository should not have any Android lifecycle attached to it and Kotlin has no destructors, how can I unsubscribe to the Observable just before my Repository is destroyed to avoid memory leaks?

Abdul Mateen
  • 1,418
  • 1
  • 14
  • 32

0 Answers0