Minimizing Realm File Size: Practical approach

John

I have a Realm db which is written to asynchronously, and the file size seems to grow exponentially during an initial load from a Rest API. It continues to grow after I have finished writing to it, topping out at 1.5GB.

Using a writeCopyToPath, the underlying data is 1.5 Mb.

Below is my insert command:

dispatch_async(dispatch_queue_create("background", nil)) {
let realm = try! Realm()
let this_activity = DataManager().getExerciseById(activity_id)
if this_activity != nil {
for (_, subJson) in data_ball["mapPoints"] {
    let  map_point = MapPoint(this_activity:this_activity!, json: subJson)
    try! realm.write {
        realm.add(map_point)
    }
 }   
}

To query I have a data manager which is instantiated by each ViewController (but not held on to after it returns with data). The Data Manager has query methods like this:

func getSegments(activity_id:String) -> [Dictionary<String, AnyObject>]{
    var intervals:[Dictionary<String, AnyObject>] = []
    let realm = try! Realm()
    let predicate = NSPredicate(format: "id == %@", activity_id)
    let intervals = realm.objects(Segment).filter(predicate).sorted("startTime", ascending: true)
    for interval in intervals {
        intervals.append(interval.toDictionary())
    }
    return intervals
}

These queries and insert operations can happen during the same time period. What strategies should I use to stop it from growing like this?

bdash

It's likely you're holding a reference to an older version of the data, preventing it from being reclaimed. Take a look at the File size & tracking of intermediate versions section of Realm's documentation for more information.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Realm database file size

From Dev

Realm file size is too large

From Dev

How does the size of a realm-file develop?

From Dev

Practical use of @Ignore in Realm?

From Dev

Minimizing "idle" writes on a file system

From Dev

How to minimizing android app cache size

From Dev

Minimizing the size of debugging information for testing at a remote location

From Dev

Excessive difference in realm file size when storing different NSData

From Dev

Java Deprecated APIs and SuppressWarnings "deprecation" - practical approach

From Dev

Fitnesse and enormous amount of files in VCS - practical approach?

From Dev

Realm shared table size

From Dev

Realm: setting NSURLIsExcludedFromBackupKey for realm file

From Dev

Best file upload approach

From Dev

ExtJS file load approach

From Dev

Minimizing the number of groups by merging them without exceding a certain group size

From Dev

Restructuring table elements on minimizing to mobile size using Bootstrap

From Dev

How to display image while minimizing window size to mobile view

From Dev

What's the most practical approach to handling null inequality?

From Dev

What is the best approach for calculating index size

From Dev

Realm file could not be opened

From Dev

Realm.io Removing the realm file

From Dev

Find path for Realm file with Realm React Native to use with Realm Browser

From Dev

Practical parameter file reading in java

From Dev

Practical use for moving file descriptors

From Dev

practical usage of /etc/networks file

From Dev

Realm app size in comparison to Core Data

From Dev

Realm: How to get the current size of the database

From Dev

Can't reduce size Realm adds to app

From Dev

Does a Realm table have a size limitation?

Related Related

HotTag

Archive