title: Kotlin lazy usage
body: <p>I'm currently using Realm in my application, and to make sure i manage Realm instances correctly, i introduced in my base Activity a variable like this:</p>
  
  <pre><code>protected val realm: Realm by lazy {
          Realm.getDefaultInstance()
  }
  </code></pre>
  
  <p>And then in onDestroy i do this:</p>
  
  <pre><code>override fun onDestroy() {
      super.onDestroy()
      realm.close()
  }
  </code></pre>
  
  <p>And then i realised this is a waste. If the current activity doesn't use realm, it will open and immediately close in <code>onDestroy</code>.</p>
  
  <p>So i updated to this:</p>
  
  <pre><code>    private var usedRealm = false
  
      protected val realm: Realm by lazy {
          usedRealm = true
          Realm.getDefaultInstance()
      }
  
  override fun onDestroy() {
          super.onDestroy()
  
          if (usedRealm) {
              realm.close()
          }
      }
  </code></pre>
  
  <p>Is there any way to accomplish the same, without the extra flag?</p>