memory leak with core data deleting object process
Dear communtity. I has a very strange leak, which i can't catch up by instruments. Application eat a memory very quickly from 200M to 450M for one cycle of removing. Call threes list for objects list show me that a problem in NSManagedObjectContext NSFetchRequest-> processRecentChanges-> propagatePendingDeletesAtEndOfEvent. Data amount is not big, current sqllite store is 37Mb, and memory doesn't free after process is done.
NSError *error = nil;
NSManagedObjectContext *moc = [self managedObjectContext];
NSFetchRequest *requestCarrier = [[NSFetchRequest alloc] init];
[requestCarrier setEntity:[NSEntityDescription entityForName:@"DestinationsListForSale"
inManagedObjectContext:moc]];
[requestCarrier setPredicate:[NSPredicate predicateWithFormat:@"(carrier.name == %@)",
carrierName]];
NSArray *destinationsListsForSale = [moc executeFetchRequest:requestCarrier error:&error];
if (error) NSLog(@"Failed to executeFetchRequest to data store: %@", [error localizedDescription]);
for (NSManagedObject *destinationForSale in destinationsListsForSale) [moc deleteObject:destinationForSale];
[requestCarrier release], requestCarrier = nil;
destinationsListsForSale = nil;
requestCarrier = [[NSFetchRequest alloc] init];
[requestCarrier setEntity:[NSEntityDescription entityForName:@"DestinationsListWeBuy" inMana开发者_如何学运维gedObjectContext:moc]];
[requestCarrier setPredicate:[NSPredicate predicateWithFormat:@"(carrier.name == %@)", carrierName]];
NSArray *destinationsListsWeBuy = [moc executeFetchRequest:requestCarrier error:&error];
if (error) NSLog(@"Failed to executeFetchRequest to data store: %@", [error localizedDescription]);
for (NSManagedObject *destinationWeBuy in destinationsListsWeBuy) [moc deleteObject:destinationWeBuy];
[requestCarrier release], requestCarrier = nil;
destinationsListsWeBuy = nil;
SOLUTION v.1 rebuild code to move out problem
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for (NSManagedObject *destination in destinationsList)
{
[moc deleteObject:destination];
if (x % 10 == 0) {
[moc save:&error];
if (error) NSLog(@"Failed to save to data store removePreviousDestinationsFromMainDatabaseForCarrier: %@", [error localizedDescription]);
[pool drain],pool = nil;
pool = [[NSAutoreleasePool alloc] init];
}
x++;
}
Have you tried just fetching the NSMangedObjectID
in your code, as suggested in this answer?
What kind of size data set are you running this on? Are you sure it's really a leak and not just normal memory usage increase associated with dealing with a very large data set?
精彩评论