Hello,
I am bulding app with ability to record video, audio and images. Every media is stored with CoreData entity and its binary data attribute with External storage (option for binary data in Core Data entity). For example one record can have many videos with relation below:
https://www.dropbox.com/s/jy5lftqde083gye/Screenshot%202017-08-08%2008.33.54.png?dl=0
https://www.dropbox.com/s/yus0jncxct9bw6l/Screenshot%202017-08-08%2008.34.23.png?dl=0
So far everything works well but during some performance testing I found that the app is not releasing CoreData object properly or at least predictably (for me).
First issue is that when I delete object from context and save it, it still remains in persistent memory because I can find it with my own predicated fetch. But for example default fetch for TableView (that code which is generated when you create new project) ignores the deleted object. I delete Record objects e.g. from table view this way:
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
let context = fetchedResultsController.managedObjectContext
let object:Record = fetchedResultsController.object(at: indexPath) as! Record
object.deleted_at = NSDate()
context.delete(object)
do {
try context.save()
print("saved")
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}Next issue is that I am not sure if cascading deletion is performed in this moment...
Which points me to third and last issue - the binary data files remain in app memory (checked with downloading App Container via Xcode). This major issue causes the app uncontrollably "expands".
I was believing that External storage solves this issue automatically. Even when I manually nil the variable which holds the binary data, real file still remains in persistent memory.
So questions may sound like this:
1. When Core Data releases object really permanently from persistent memory?
2. When is External binary data deleted from persistent memory?
Thanks all of you for your help!
J.