drewmccormack / ensembles

A synchronization framework for Core Data.
MIT License
1.63k stars 132 forks source link

crash because Memory #251

Closed JeanetteMueller closed 7 years ago

JeanetteMueller commented 7 years ago

Hello, i have lots of crashes because of low memory on sync and/or merge with Ensemble.

This is my imprementation: https://github.com/JeanetteMueller/JxUtils/blob/main/Swift3/CoreData/JxCoreDataStoreWithSync.swift

dont know how to fix this problems :(

i have 3 different models in coredata and in use something around 10.000 entities.

Hope you can help.

JeanetteMueller commented 7 years ago

i use this to set global identifiers:

` override func persistentStoreEnsemble(_ ensemble: CDEPersistentStoreEnsemble!, globalIdentifiersForManagedObjects objects: [Any]!) -> [Any]! {

    let items = objects as! [NSManagedObject]

    return items.map {

        if $0 is ManagedPodcast{
            return $0.value(forKey: "feed") as Any
        }
        if $0 is ManagedEpisode{
            let episode = $0 as! ManagedEpisode

            let identifier = episode.guid as Any
            //print(identifier)
            return identifier
        }

        if $0 is ManagedGroup{
            let group = $0 as! ManagedGroup

            if group.groupType == ManagedGroupType.allUnread.rawValue ||
                group.groupType == ManagedGroupType.allFavourite.rawValue ||
                group.groupType == ManagedGroupType.allVideo.rawValue ||
                group.groupType == ManagedGroupType.allDownloaded.rawValue ||
                group.groupType == ManagedGroupType.allUnsorted.rawValue{

                return String.init(format: "groupType_%d", group.groupType) as Any

            }else{
                return group.guid as Any
            }
        }

        return NSNull()
    }`
drewmccormack commented 7 years ago

I don't think this method is the cause of the memory. I think just the amount of data you have is enough to push an iOS device over the limit.

I recommend you take a look at the Model chapter of the book (http://leanpub.com/ensembles). It describes using batch migration to reduce memory usage.

Update: I just realised you are probably using Ensembles v1, the open source version. The batch support is only in the commercial Ensembles v2 version.