iOS应用程序刷新期间内存泄漏

时间:2015-07-04 16:50:11

标签: ios xcode nsarray

我无法找到内存泄漏。每当我“刷新”我的内存使用量就会增加。每次“刷新”时都会调用此函数。当我需要明确删除/解除分配时,以及当我不需要时,我不是很有经验。

-(void)convertJSONArrayToProfiles:(NSArray*)profilesJSON
{
    //Remove and Fill Profiles Array with empty profiles
    //This is to make sure we have stock images for the empty ones
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    [self.profiles removeAllObjects];
    [self removeGestureRecognizersFromImages];
    for (int i = 0; i < appDelegate.gNumberOfProfilesToGather; i++) {
        Profile *profile = [[Profile alloc]init];
        profile.profilePic = NULL;
        [self.profiles insertObject:profile atIndex:i];
    }

    //Replace the Empty Profiles with the real ones
    //This is to make sure we have stock images for the empty ones
    int profileCount = 0;
    for (NSDictionary* dict in profilesJSON)
    {
        Profile *profile = [[Profile alloc]init];

        profile.firstName = [dict objectForKey:@"first_name"];
        profile.interest1 = [dict objectForKey:@"interest_1"];
        profile.interest2 = [dict objectForKey:@"interest_2"];
        profile.occupation = [dict objectForKey:@"occupation"];
        profile.distinguished = [[dict objectForKey:@"distinguished"] intValue];

        //If the profile doesn't have a profile image, set it to the Stock image
        if (([dict objectForKey:@"profile_pic_path"] == [NSNull null]) || ([[dict objectForKey:@"profile_pic_path"] isEqual: @"default"])){
            profile.profilePic=NULL;
        }
    //If the returned profile has a profile image, set the profile image to URL returned
        else {
        //The image data is Base64 encoded inorder to pass it through JSON
        //Have to decode it and then store it

            NSData *decodedImage = [[NSData alloc] initWithBase64EncodedString:[dict objectForKey:@"profile_pic_path"] options:0];
            profile.profilePic  = [UIImage imageWithData:decodedImage];

        }

        //Add profile to Profiles array
        [self.profiles replaceObjectAtIndex:profileCount withObject:profile];
        profileCount++;

    }

    NSLog(@"Profile Gathered = %d", profileCount);

}

0 个答案:

没有答案