Iphone 为什么executeFetchRequest:fetchRequest内存泄漏?

Iphone 为什么executeFetchRequest:fetchRequest内存泄漏?,iphone,ios,objective-c,objective-c-blocks,stackmob,Iphone,Ios,Objective C,Objective C Blocks,Stackmob,仪器显示以下代码泄漏,如果我注释掉此代码,则没有泄漏 NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; // Edit the entity name as appropriate. NSEntityDescription *entity = [NSEntityDescription entityForName:USER_CORE_DATA inManagedObjectContext:self.man

仪器显示以下代码泄漏,如果我注释掉此代码,则没有泄漏

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

    // Edit the entity name as appropriate.

    NSEntityDescription *entity = [NSEntityDescription entityForName:USER_CORE_DATA inManagedObjectContext:self.managedObjectContext];

    [fetchRequest setEntity:entity];

    NSPredicate *predicte = [NSPredicate predicateWithFormat:@"username == %@", [[User defaultManager] savedUsername]];
    [fetchRequest setPredicate:predicte];

    // set any predicates or sort descriptors, etc.

    // execute the request
    [self.managedObjectContext executeFetchRequest:fetchRequest onSuccess:^(NSArray *results) {

    } onFailure:^(NSError *error) {

        NSLog(@"Error fetching: %@", error);

    }];
    [fetchRequest release];
具体地说,上述代码中的这一行:

[self.managedObjectContext executeFetchRequest:fetchRequest onSuccess:^(NSArray *results)

这似乎是fetchRequest和/或块的泄漏。任何帮助都将不胜感激。

看来
executeFetchRequest:onSuccess:onFailure:
是您在NSManagedObjectContext类别中定义的函数。确保传递给
onSuccess
块的NSArray对象实例已自动删除。

事实上,StackMob的代码有漏洞,我从那里下载了源代码并修复了它

- (NSString *)primaryKeyField
{
    NSString *objectIdField = nil;

    // Search for schemanameId
    objectIdField = [[self SMSchema] stringByAppendingFormat:@"Id"];
    if ([[[self entity] propertiesByName] objectForKey:objectIdField] != nil) {
        return objectIdField;
    }

    objectIdField = nil;  // This line was missing and causing a leak

    // Search for schemaname_id
    objectIdField = [[self SMSchema] stringByAppendingFormat:@"_id"];
    if ([[[self entity] propertiesByName] objectForKey:objectIdField] != nil) {
        return objectIdField;
    }

    objectIdField = nil;  // This line was missing and causing a leak

    // Raise an exception and return nil
    [NSException raise:SMExceptionIncompatibleObject format:@"No Attribute found for `entity %@ which maps to the primary key on StackMob. The Attribute name should match one of the following formats: lowercasedEntityNameId or lowercasedEntityName_id.  If the managed object subclass for %@ inherits from SMUserManagedObject, meaning it is intended to define user objects, you may return either of the above formats or whatever lowercase string with optional underscores matches the primary key field on StackMob.", [[self entity] name], [[self entity] name]];`

对于这些复杂性。。。我把它们转换成圆弧。那不是一个函数,它是一个块。@AnoopVaidya C'mon。。executeFetchRequest:onSuccess:onFailure:是一个函数,传递给onSuccess和onFailure的参数是块executeFetchRequest:onSuccess:onFailure:'是StackMob库中定义的函数,我无法查看它。我可以试着自己释放NSArray,看看这是否会改变什么。当我试图释放NSArray结果时,我得到了一个过度释放崩溃。好的。然后数组被自动释放,这很好。