Realm Blog

Realm Java 0.75

We recently released a Realm Java update to this website and to Maven. This release is a big one! Based on all your great suggestions, bug reports, and forum discussions, we made a hard decision to implement some breaking changes to the API. Here’s how this release impacts your code.

Realm now implements Closeable

Realm uses native resources and the standard Android and Java platform guidelines state that finalize() cannot be trusted for cleaning up such resources. This means that whenever you obtain an instance of Realm you should have a matching close() statement somewhere in your code.

Calling the close() method will allow Realm to free-up resources (disk & memory) by properly disposing of the Realm objects after you are done with them. This can be particularly helpful if you are seeing many out-of-memory errors, or large file sizes on disk (usually indicative of previously improperly-closed Realms.) See the documentation for more details.

Changes to Sorting RealmResults

For better speed and stability, sorting an instance of RealmResults is now an in-place operation. This means it’ll operate on the same instance it is called on instead of returning a new one.

We also added sorting capabilities to allObjects() and findAll() so you can still obtain sorted query results in one line of code. See the documentation for more details.

Compact your Realm files

Realm now provides methods to compact Realm files. This is very useful if you want to share your database over the network or ensure your app takes up as little space as possible. The compacted file can be opened directly without the need of any further operation. See compactRealmFile() for details.

Please be careful to only apply compaction to a Realm file if the Realm is not open. In general, you should only use the method when your app starts up and before any instances of Realm have been opened (this includes migration too, as migrations will open at least one realm instance).

Please note that compaction is not necessary in most cases, as unused space will eventually be reclaimed automatically for future writes to the Realm file.

Auto-Refresh changes

If a current thread has a Looper attached, Realm instances will automatically auto-refresh. We deprecated the Realm constructors that accepted the auto-refresh argument; they will be removed in 0.76.0.


Stability has improved in a few ways. Most importantly, we restored correct behavior of toString(), hashCode() and equals() in the presence of cyclic data structures. Also, we added the ability to remove items while iterating an instance of RealmResults.

Thanks for reading. Now go forth and build amazing apps with Realm! As always, we’re around on the mailing list, Stack Overflow, GitHub, and Twitter.

Realm Team

At Realm, our mission is to help developers build better apps faster. We provide a unique set of tools and platform technologies designed to make it easy for developers to build apps with sophisticated, powerful features — things like realtime collaboration, augmented reality, live data synchronization, offline experiences, messaging, and more.

Everything we build is developed with an eye toward enabling developers for what we believe the mobile internet evolves into — an open network of billions of users and trillions of devices, and realtime interactivity across them all.

Get more development news like this