Skip to content Skip to sidebar Skip to footer

App Size Increase Due To Realm Android

I am adding some data into realm database after every 15 sec through a service. After a whole night, the size of app become 350mb due to realm, its confirm.. But if i delete that d

Solution 1:

Realm currently doesn't automatically reclaim the space used by your database, but it will be reused if you later add data again.

If you wish to free the disk space you can use Realm.compactRealm(): https://realm.io/docs/java/latest/api/io/realm/Realm.html#compactRealm-io.realm.RealmConfiguration-

However, a file size of 350 MB sounds like quite a lot. Are you really inserting that much data?

Solution 2:

    Realm realm = null;
    RealmConfiguration config = new RealmConfiguration.Builder(MyApplication.appInstance().getApplicationContext())
            .deleteRealmIfMigrationNeeded()
            .build();
    try {
        realm = Realm.getInstance(config);
    } catch (Exception e) {
    }

    RealmResults<MqttLocationModel> result2 = realm.where(MqttLocationModel.class).equalTo("uid", objectId).findAll();
    Log.e("Delted  object id",""+objectId);
    Log.e("Delted DB Size",""+result2.size());
    realm.beginTransaction();
    result2.clear();
    realm.commitTransaction();

    RealmResults<MqttLocationModel> result3 = realm.where(MqttLocationModel.class).equalTo("uid", objectId).findAll();
    Log.e("Delted final DB Size",""+result3.size());

    realm.close();

    realm.compactRealm(config);

Solution 3:

Your service executes on a background thread, so you probably have a single realm open on a BACKGROUND THREAD for the whole duration of the sync procedure, thus creating multiple versions of the Realm.

If this is true, you should either close and reopen the Realm after a transaction, or use waitForChange ().

Post a Comment for "App Size Increase Due To Realm Android"