Realm large db size due to frequent updates
<p>I have a thread running every second that updates Realm database fields every second. While the data being updated is tiny, I've found out that updates still increase the database filesize until you explicitly clean it with <code>Realm.compressRealm()</code> so within an hour or two the db size is 50MB+ and will easily bloat up to 750MB+ in a short period as well.</p>

<p>I am closing the Realm with <code>realm.close()</code> in the Activity <code>onStop()</code> and also closing the new Realm instance I create in the timer thread:</p>

<pre><code>public void checkDealersTimer() {
    RealmResults&lt;Dealers&gt; dealersLookup = realm.where(Dealers.class).equalTo("thedealers","thedealers").findAll();
    dlr = dealersLookup.get(0);

    if (dlr.getPerSecond() != 0.00) {
        if (dealerTimer == null) {
            dealerTimer = new Timer();
            dealerTimer.scheduleAtFixedRate(new TimerTask() {
                @Override
                public void run() {
                    Realm drealm;
                    drealm = Realm.getDefaultInstance();

                    RealmResults&lt;Dealers&gt; dealersLookup = drealm.where(Dealers.class).equalTo("thedealers","thedealers").findAll();
                    dlr = dealersLookup.get(0);

                    drealm.beginTransaction();
                    dlr.setEarnings(dlr.getEarnings()+dlr.getPerSecond());
                    drealm.commitTransaction();
                    drealm.close();
                }
            }, 0, 1000);

        }
    }
}
</code></pre>

<p>This timer is the only place I use Realm outside of the UI thread, and the only place I am making updates so frequent, so I am assuming the "leak" is coming from here though I cannot be sure. The filesize creeps up wether the app is visible or not, but only when it is running.</p>

<p>Here's another user with a similar issue:
<a href="https://stackoverflow.com/questions/37453353/app-size-increase-due-to-realm-android">App size increase due to realm android</a></p>

<p>If that is believed to be the solution, I cannot find the correct way to call <code>Realm.compressRealm()</code> since the db is supposed to be updating every second when you're using it, and I can only close the Realm <code>onDestroy()</code> not <code>onStop()</code> (and <code>Realm.compressRealm()</code> requires you to close all Realms)</p>

<p>I appreciate any input, thank you!</p>