ios - Terminated due to memory issue error since migrating to Swift 3 -
i using ensembles framework sync data icloud. working fine until migrated swift 3.
the framework in objective-c , appdelegate
functions have migrated swift 3; have had issues since. call appdelegate.syncwithcompletion
throughout app when saving changes nsmanagedobjects
.
here's appdelegate
functions
// mark: ensembles var cloudfilesystem: cdecloudfilesystem! var ensemble: cdepersistentstoreensemble! func syncwithcompletion(completion:@escaping (_ completed:bool) -> void) { if !ensemble.isleeched { ensemble.leechpersistentstore { error in if error != nil { print("cannot leech \(error!.localizeddescription)") completion(false) } else { print("leached!!") completion(true) } } } else { ensemble.merge{ error in if error != nil { print("cannot merge \(error!.localizeddescription)") completion(false) } else { print("merged!!") completion(true) //nsnotificationcenter.defaultcenter().postnotificationname("updated-db", object: nil) } } } } func persistentstoreensemble(_ ensemble: cdepersistentstoreensemble, didsavemergechangeswith notification: notification) { managedobjectcontext.performandwait { print("database updated icloud") self.managedobjectcontext.mergechanges(fromcontextdidsave: notification notification) notificationcenter.default.post(name: nsnotification.name(rawvalue: "updated-db"), object: nil) } } private func persistentstoreensemble(ensemble: cdepersistentstoreensemble!, globalidentifiersformanagedobjects objects: [anyobject]!) -> [anyobject]! { return (objects nsarray).value(forkeypath: "uniqueidentifier") as! [anyobject] }
i turned icloud drive off , following error when running app; cpu on 100%, memory , energy high.
message debugger: terminated due memory issue
when icloud drive on syncing , merging data following
could not load objective-c class information. reduce quality of type information available.
when investigating further instruments takes me following function in ensembles framework; dispatch_async(queue,^{
line more specifically.
#pragma mark merging store modification events - (void)mergeeventswithcompletion:(cdecompletionblock)completion { nsassert([nsthread ismainthread], @"mergeevents... called off main thread"); neweventuniqueid = nil; // setup context accessing main store nserror *error = nil; nspersistentstorecoordinator *coordinator = [[nspersistentstorecoordinator alloc] initwithmanagedobjectmodel:managedobjectmodel]; nspersistentstore *persistentstore = [coordinator addpersistentstorewithtype:nssqlitestoretype configuration:nil url:storeurl options:self.persistentstoreoptions error:&error]; if (!persistentstore) { [self failwithcompletion:completion error:error]; return; } self.managedobjectcontext = [[nsmanagedobjectcontext alloc] initwithconcurrencytype:nsprivatequeueconcurrencytype]; [self.managedobjectcontext performblockandwait:^{ self.managedobjectcontext.persistentstorecoordinator = coordinator; self.managedobjectcontext.undomanager = nil; }]; nsmanagedobjectcontext *eventstorecontext = self.eventstore.managedobjectcontext; // integrate on background queue dispatch_async(queue,^{ @try { __block nserror *error; // apply changes bool integrationsucceeded = [self integrate:&error]; if (!integrationsucceeded) { [self failwithcompletion:completion error:error]; return; } // if no changes, complete __block bool haschanges; [managedobjectcontext performblockandwait:^{ haschanges = managedobjectcontext.haschanges; }]; if (!haschanges) { [self completesuccessfullywithcompletion:completion]; return; } // create id of new event // register event in case of crashes neweventuniqueid = [[nsprocessinfo processinfo] globallyuniquestring]; [self.eventstore registerincompleteeventidentifier:neweventuniqueid ismandatory:no]; // create merge event cdeeventbuilder *eventbuilder = [[cdeeventbuilder alloc] initwitheventstore:self.eventstore]; eventbuilder.ensemble = self.ensemble; cderevision *revision = [eventbuilder makeneweventoftype:cdestoremodificationeventtypemerge uniqueidentifier:neweventuniqueid]; // repair inconsistencies caused integration bool repairsucceeded = [self repairwithmergeeventbuilder:eventbuilder error:&error]; if (!repairsucceeded) { [self failwithcompletion:completion error:error]; return; } // commit (save) changes bool commitsucceeded = [self commitwithmergeeventbuilder:eventbuilder error:&error]; if (!commitsucceeded) { [self failwithcompletion:completion error:error]; return; } // save changes event context __block bool eventsavesucceeded = no; [eventstorecontext performblockandwait:^{ bool isunique = [self checkuniquenessofeventwithrevision:revision]; if (isunique) { [eventbuilder finalizenewevent]; eventsavesucceeded = [eventstorecontext save:&error]; } else { error = [nserror errorwithdomain:cdeerrordomain code:cdeerrorcodesaveoccurredduringmerge userinfo:nil]; } [eventstorecontext reset]; }]; if (!eventsavesucceeded) { [self failwithcompletion:completion error:error]; return; } // notify of save [self.managedobjectcontext performblockandwait:^{ if (didsaveblock) didsaveblock(managedobjectcontext, saveinfodictionary); }]; saveinfodictionary = nil; // complete [self completesuccessfullywithcompletion:completion]; } @catch (nsexception *exception) { nsdictionary *info = @{nslocalizedfailurereasonerrorkey:exception.reason}; nserror *error = [nserror errorwithdomain:cdeerrordomain code:cdeerrorcodeunknown userinfo:info]; [self failwithcompletion:completion error:error]; } }); }
does know causing errors , and how can resolve them? seems keep looping on code, nsmanagedobjects keep getting duplicated.
ps: project worked fine in swift 2.2.
Comments
Post a Comment