Hilt: When does object gets destroyed provided in ApplicationComponent?

Viewed 242
@Module
@InstallIn(SingletonComponent::class)
object AnalyticsModule {
  @Provides
  fun provideAnalyticsService(): AnalyticsService {
      return AnalyticsServiceImpl()  
  }
}

@AndroidEntryPoint
class ExampleActivity: AppCompatActivity() {
  @Inject lateinit var service: AnalyticsService
}

Since I wanted to use AnalyticsService anywhere in the app, I'm providing it in SingletonComponent/ ApplicationComponent.

  1. Does service object gets destroyed when Activity is destroyed?
  2. Or it will get garbage collected only when Application is destroyed?
0 Answers
Related