0

Last day I started using Realm as Android storage rather than Sqlite.

Everything went well till I searched for some pros and cons; someone said that it doesn't support delete (I was shocked). but I found that there is a delete section in documentation and I implemented sample application that adds 150 row and then I 'delete' them as the following answer said.

The size of list after deleteing is 0 which is logically right. But when I checked the size of myDB.realm file in the 'data/data/' path in the emulator, I found it the same size of the file before deleting. So does Realm flag items as deleted or physically deleting it?

Community
  • 1
  • 1
Amt87
  • 5,493
  • 4
  • 32
  • 52

1 Answers1

1

The data is physically deleted, but right now Realm doesn't automatically reclaim the used space (it is on our TODO). In the mean time, you can manually call Realm.compactRealm(realmConfig) if you want to reclaim the space: https://realm.io/docs/java/latest/api/io/realm/Realm.html#compactRealm-io.realm.RealmConfiguration-

Christian Melchior
  • 19,978
  • 5
  • 62
  • 53
  • Thanks, it worked for me when using Realm.compactRealm(realmConfig). But when I used the configuration that has been set in Application class like this Realm.compactRealm(mRealm.getConfiguration()); it didn't work. Any Idea? – Amt87 May 03 '16 at 13:32
  • 1
    You cannot compact an open Realm, which was most likely what was happening. – Christian Melchior May 03 '16 at 14:10