令人惊讶的iPhone泄漏

时间:2010-05-21 21:36:52

标签: iphone memory-leaks

所以我在我的应用程序上运行仪器,并且我可以发誓我正在做正确的泄漏。

+ (NSMutableArray *)decode:(NSDictionary *)encoded_faculty_array
{   
    NSArray *faculty_id_data = [encoded_faculty_array objectForKey:@"faculty_id"];
    NSArray *faculty_first_name = [encoded_faculty_array objectForKey:@"first_name"];
    NSArray *faculty_last_name = [encoded_faculty_array objectForKey:@"last_name"];

    NSMutableArray* faculty_array = [[NSMutableArray alloc] init];

    for(int a = 0; a < [faculty_id_data count]; a++)
    {
        Faculty *new_fac = [[Faculty alloc] initWithFacultyId:[Dearray clean:[faculty_id_data objectAtIndex:a] withDefault:@"0"]                                
                                            andFirstName:[Dearray clean:[faculty_first_name objectAtIndex:a] withDefault:@"Name not found"] 
                                            andLastName:[Dearray clean:[faculty_last_name objectAtIndex:a] withDefault:@" "]    
                                            andBio:nil 
                                            andDegrees:nil 
                                            andTitle:nil];
        [faculty_array addObject:new_fac];
        [new_fac release];
    }

    [faculty_array autorelease];
    return faculty_array;
}

它报告了new_fac的泄漏。我打电话后立即发布了它。知道可能导致这个问题的原因吗?

感谢。

修改

以下是初始化Faculty实例new_fac的代码:

- (id) initWithFacultyId:(NSString *)new_id andFirstName:(NSString *)new_first_name andLastName:(NSString *)new_last_name andBio:(NSString *)new_bio andDegrees:(NSString *)new_degrees andTitle:(NSString *)new_title 
{ 
    if (self = [super init]) { 
        self.faculty_id = new_id; 
        self.first_name = new_first_name; 
        self.last_name = new_last_name; 
        self.bio = new_bio; 
        self.degrees = new_degrees; 
        self.title = new_title; 
    } 
    return self; 
} 

1 个答案:

答案 0 :(得分:0)

您可以尝试检查是否有Faculty的属性,并确保正确释放这些NSStrings(firstName,lastName等)。

如果这些字符串是“保留”的属性,则应在Faculty dealloc中发布。