compactOnLaunch

fun compactOnLaunch(callback: CompactOnLaunchCallback = Realm.DEFAULT_COMPACT_ON_LAUNCH_CALLBACK): S

Sets a callback for controlling whether the realm should be compacted when opened.

Due to the way Realm allocates space on disk, it is sometimes the case that more space is allocated than what is actually needed, making the realm file larger than what it needs to be. This mostly occurs when writing larger binary blobs to the file.

The space will be used by subsequent writes, but in the interim period the file will be larger than what is strictly needed.

This method makes it possible to define a function that determines whether or not the file should be compacted when the realm is opened, optimizing how much disk size is used.

Parameters

callback

The callback called when opening the realm file. The return value determines whether or not the file should be compacted. If not user defined callback is defined, the default callback will be used. See Realm.DEFAULT_COMPACT_ON_LAUNCH_CALLBACK for more details.