title: Realm - how to close realm instance with async transaction
body: <p>I have a problem with understanding what is good practice on closing Realm instance, whenever I am running async transaction. </p>
  
  <p>In my application I have many controllers and I do not pass into them Realm instance from activity, instead I create a new one each time it is needed and close it as soon as work is done.</p>
  
  <p>However recently I found out that it is not working correctly, if I am closing realm instance when it is running async transaction.</p>
  
  <pre><code>Realm cacheRealm = RealmDelegate.getCacheRealm();
  
  cacheRealm.executeTransaction(realm -&gt; {
      doSomeWork(response);
      realm.copyToRealmOrUpdate(response);
  }, callback);
  cacheRealm.close();
  </code></pre>
  
  <p>This code above has one big problem, that callback is never launched, since I am closing realm instance before transaction is finished.</p>
  
  <p>Therefore I am not sure how am I supposed to handle this situation. Am I supposed to pass instance of Realm object into each controller from activity or fragment, and handle closing of realm instances only over there? Or maybe there are other more elegant solutions to this problem?</p>
  
  <p>Also another thing that I am wondering about is what happens, if I won't close the Realm db, and is there a way to check if all instances of Realm has been closed?</p>