MergeChangesFromContextDidSaveNotification consumes memory

I have two NSManagedObjectContext, one for ui and one for background tasks. I am trying to merge changes in a UIcontext whenever the background has changed. But whenever I call

mergeChangesFromContextDidSaveNotification:notification

It is just starting to eat memory (it will go up to 1 GB on the simulator) and causes a crash.

Of course, I'm setting up a notification:

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(coreUpdateFromApp:)
                                                 name:NSManagedObjectContextDidSaveNotification
                                               object:nil];

and also tried to do a merge in the main thread, etc. Bad luck!

I found out that the URIR problem is the problem. For some reason they continue to call him. (Apple code is not mine)

Please note that I allow it to work for a second, and it uses 64.95MB, it will grow pretty fast with the same call tree. If I continue to execute it, it will also hurt osx!

Profiler result

+4
2

object:nil. .

.

+4

, , Google Analytics , , Google Analytics.

, , . , .

,

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(managedObjectContextDidSave(_:)), name: NSManagedObjectContextDidSaveNotification, object: nil)

func managedObjectContextDidSave(notification: NSNotification) {
    if notification.object?.persistentStoreCoordinator != self.persistentStoreCoordinator {
        return
    }
    //do remaining task here.
}
0

Source: https://habr.com/ru/post/1536016/


All Articles