开发者

Core Data NSSortDescriptor causing memory leak

I am getting a memory leak when I add a sort descriptor to my Fetch Request in Core Data. If I comment out the NSSortDescriptor block it runs without a memory leak in Instruments.

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Pools" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"game.league.id=%i",[lid intValue]];
[fetchRequest setPredicate:predicate];

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"game.date" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
[s开发者_运维技巧ortDescriptors release];
[sortDescriptor release];

NSError *error;
NSArray *items = [managedObjectContext executeFetchRequest:fetchRequest error:&error];

// Do Something

[fetchRequest release];
[items release];

Any ideas?


In the sort descriptor, you're walking a relationship using the keypath game.date.

Your leak is probably associated with one of those objects in the keypath. It disappears when you remove the sort because then the objects in the key path don't do anything.

If you have transient properties, custom accessors, non-entity properties etc in the game entity I would look there. Custom value transformers are also a good bet.

The stack in Instrument should tell you exactly which object is leaking.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜