I've posted similar questions about different things relating to this, but have been struggling with this for about a week now, to no avail. It all comes down to this code:
NSFetchRequest *oldFetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *oldEntryEntity = [NSEntityDescription entityForName:@"Media"
inManagedObjectContext:oldContext];
[oldFetchRequest setEntity:oldEntryEntity];
[oldFetchRequest setFetchBatchSize:10];
NSArray *medias = [oldContext executeFetchRequest:oldFetchRequest error:&error];
int i = 0;
int count = [oldContext countForFetchRequest:oldFetchRequest error:nil];
NSLog(@"count: %i", count);
while (i < count) {
@autoreleasepool {
NSManagedObject *media = [medias objectAtIndex:i];
[oldContext refreshObject:media mergeChanges:NO];
NSLog(@"i: %i", i);
i++;
}
}
Count should be reaching about 250, the amount of media
items. It actually reaches about 100 before the app runs out of memory and crashes. It builds up more and more memory every time this code is run, presumably as each media
contains a number of NSData attributes, including a large one. Instruments shows memory increasing every time the code is run.
@autoreleasepool
and refreshObject:mergeChanges:
I added to try and fix this problem, but they haven't worked.
What i'm trying to do is move all of the items from this store into a new one manually, as standard migration doesn't work with large data. This is the starting point.