Can ViewModel implement LifecycleOwner?

719 Views Asked by At

I know that, ViewModels should never keep a reference to a LifecycleOwner since it keeps a reference to a context and hence this causes a memory leak. But my question is, can I implement a LifecyclerOwner for ViewModel itself? with two valid callbacks, onCreate() triggered when view model's constructor is invoked and onDestroy() triggered when view model's onCleared() is invoked. Since LifecycleOwner is just an Java interface, I think this will not cause any memory leak. But to be on safer side, I'm asking this.

0

There are 0 best solutions below