core data - Objective C For loops with @autorelease and ARC -


as part of app allows auditors create findings , associate photos them (saved base64 strings due limitation on web service) have loop through findings , photos within audit , set sync value true.

whilst perform loop see memory spike jumping around 40mb 500mb (for 350 photos , 255 findings) , number never goes down. on average our users creating around 1000 findings , 500-700 photos before attempting use feature. have attempted use @autorelease pools keep memory down never seems released.

    (finding * __autoreleasing f in self.audit.findings){         @autoreleasepool {             [f settosync:@yes];             nslog(@"%@", f.idfinding);          (findingphoto * __autoreleasing p in f.photos){             @autoreleasepool {                 [p settosync:@yes];                 p = nil;             }          }         f = nil;          }     } 

the relationships , retain cycles this

audit has strong reference finding

finding has weak reference audit , strong reference findingphoto

findingphoto has weak reference finding

what missing in terms of being able loop through these objects , set properties without causing such huge spike in memory. i'm assuming it's got many base64 strings being loaded memory when looping through never being released.

so, first, make sure have batch size set on fetch request. choose relatively small number, not small because isn't ui processing. want batch reasonable number of objects memory reduce loading overhead while keeping memory usage down. try 50 or 100 , see how goes, consider upping batch size little.

if of objects you're loading managed objects correct way evict them during processing turn them faults. that's done calling refreshobject:mergechanges: on context. - discards changes, , loop there make changes.

so, should doing batch saving objects you've modified , turning objects faults remove data memory.

so, in loop, keep counter of how many you've modified , save context each time hit count , refresh objects processed far. batch on fetch , batch size save should same number.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -