title: Lifecycle of constructor parameters in Kotlin
body: <p>I am trying to understand the lifecycle of constructor parameters in Kotlin.
  Given the following code, when will <code>FooFactory</code> class instance be available for collection by garbage collector?</p>
  <p>Since the usage of <code>FooFactory</code> is delayed, will the runtime know when to release it?</p>
  <p>Or will this create a leak if the compiler does not know when to release <code>FooFactory</code> and it will live forever?</p>
  <pre class="lang-kotlin prettyprint-override"><code>
  class Foo {
      fun doStuff() {}
  }
  
  class FooFactory {
      fun getFoo() : Foo {
          return Foo()
      }
  }
  
  class User(factory: FooFactory) {
      val x: Foo by lazy {
          factory.getFoo()
      }
  }
  
  val user = User(FooFactory())
  
  Thread.sleep(100)
  
  user.x.doStuff()
  
  Thread.sleep(100)
  </code></pre>