title: How does Dagger 2 dispose of injected fields when they are no longer needed?
body: <p>I have a question about injecting multiple fragments into the activity's fields. Currently I have such a set up (all fragments extend DaggerFragment and the activity is DaggerAppCompatActivity):</p>
  
  <pre><code>@Inject
  lateinit var fragmentOne: FragmentOne
  @Inject
  lateinit var fragmentTwo: FragmentTwo
  @Inject
  lateinit var fragmentThree: FragmentThree
  
  override fun onCreate(...) {
      ...
      startFirstFragment()
  }
  
  fun startFirstFragment() {
      supportFragmentManager.beginTransaction()
              .replace(containerId, fragmentOne).commit()
  }
  
  fun startSecondFragment() {
      supportFragmentManager.beginTransaction()
              .replace(containerId, fragmentTwo).commit()
  }
  </code></pre>
  
  <p>And everything works fine, until I add LeakCanary, which says that, when I replace first fragment with the second, the instance being replaced leaks through <code>lateinit var fragmentOne</code> as it retains the reference to the first fragment. My question is: when does dagger empty the fields, does it do it correctly and who is to blame: dagger for causing leaks, LeakCanary for false positive leak detection or something else?</p>
  
  <p>ApplicationComponent:</p>
  
  <pre><code>@ApplicationScoped
  @Component(
          modules = [
              AndroidSupportInjectionModule::class,
              ActivityBindingModule::class,
              ApplicationModule::class,
              RepositoriesModule::class,
              NetworkModule::class]
  )
  interface ApplicationComponent : AndroidInjector&lt;MyApp&gt; {
  
      override fun inject(instance: MyApp?)
  
      @Component.Builder
      interface Builder {
  
          @BindsInstance
          fun application(application: Application): Builder
          fun build(): ApplicationComponent
      }
  }
  </code></pre>
  
  <p>ActivityBindingModule:</p>
  
  <pre><code>@Module
  abstract class ActivityBindingModule {
  
      ...
  
      @ActivityScoped
      @ContributesAndroidInjector(modules = [ActivityInQuestionModule::class])
      internal abstract fun aiqActivity(): ActivityInQuestion
  
      @ActivityScoped
      @Binds
      internal abstract fun fragmentSwitcher(activityInQuestion: ActivityInquestion): FragmentSwitcher
  
  }
  </code></pre>
  
  <p>ActivityInQuestionModule:</p>
  
  <pre><code>@Module
  abstract class ActivityInQuestionModule {
  
      @FragmentScoped
      @ContributesAndroidInjector
      internal abstract fun fragmentOne(): FragmentOne
  
      @FragmentScoped
      @ContributesAndroidInjector
      internal abstract fun fragmentTwo(): FragmentTwo
  
      @FragmentScoped
      @ContributesAndroidInjector
      internal abstract fun fragmentThree(): FragmentThree
  
  }
  </code></pre>