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?
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.
Comments