Android Studio warns memory leak on context which injected with hilt @ApplicationContext

I use Hilt for DI and recently (after some update) android studio warns me on context filed annotated with @ApplicationContext for memory leaks. as far as I know I know application context will available while app is running and it shouldn’t cause memory leak but it seems lint think differently. am I wrong or it’s just a bug?

Answer

I solved this by using ApplicationContext instead of Context

class ActivityViewModel @ViewModelInject constructor(
    @ApplicationContext val context: ApplicationContext,
)

Leave a Reply

Your email address will not be published. Required fields are marked *