My core data store contains 51 Entry
entities which have a message
attribute reading "Test". Doing an NSFetchRequest for this confirms that they're all there.
I have another part of my method however, which will be used for memory intensive purposes, dealing with large chunks of NSData, and so I need to call [oldContext reset];
quite often.
I have a memory intensive method which accesses a lot of NSData from my MOC. As such, it regularly calls [oldContext reset];
. Without this line, it runs out of memory.
I've discovered that by using this though, it's not returning the correct results. To test this, I commented out the data intensive code, leaving me with code which returned the message
attribute, 51 of which are set to "Test" (confirmed by a separate NSFetchRequest).
Using [oldContext reset];
however, it only returns 6 results with the message set to "Test". This is the code I'm using:
NSFetchRequest *oldFetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *oldEntryEntity = [NSEntityDescription entityForName:@"Entry"
inManagedObjectContext:oldContext];
[oldFetchRequest setEntity:oldEntryEntity];
[oldFetchRequest setFetchBatchSize:10];
[oldFetchRequest setIncludesPropertyValues:NO];
NSArray *entrys = [oldContext executeFetchRequest:oldFetchRequest error:&error];
int totalEntries = [oldContext countForFetchRequest:oldFetchRequest error:nil];
int i = 0;
while (i < totalEntries) {
@autoreleasepool {
Entry *entry = [entrys objectAtIndex:i];
NSLog(@"message 1: %@", [entry valueForKey:@"message"]);
[oldContext reset];
i++;
}
}
Any thoughts as to why it's not giving the 51 "Test" results it should do?