Memory UITableView增加了内存

Memory UITableView增加了内存,memory,tableview,Memory,Tableview,我创建了一个带有tableview的应用程序。它包含使用JSON从URL请求的名称列表。然而,当我持续上下滚动很长一段时间(我使用右边的索引列表来加快进程)时,内存会不断增加。我只在我的设备上测试了它,并在xcode中跟踪内存使用情况。当它达到大约50-60MB时,我的iPhone重新启动(在日志窗口中甚至没有看到崩溃:P) 当我在tableview中来回查看下一个视图时,我的内存也会不断增加(因此,通过始终选择相同的单元格)。但我首先要解决tableview问题。这是我的密码: - (UITa

我创建了一个带有tableview的应用程序。它包含使用JSON从URL请求的名称列表。然而,当我持续上下滚动很长一段时间(我使用右边的索引列表来加快进程)时,内存会不断增加。我只在我的设备上测试了它,并在xcode中跟踪内存使用情况。当它达到大约50-60MB时,我的iPhone重新启动(在日志窗口中甚至没有看到崩溃:P)

当我在tableview中来回查看下一个视图时,我的内存也会不断增加(因此,通过始终选择相同的单元格)。但我首先要解决tableview问题。这是我的密码:

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger voornaamTag = 1;
    NSInteger tussenvoegselTag = 2;
    NSInteger achternaamTag = 3;

    static NSString *cellIdentifier = @"xCell";

    NSString *key = [[self sectionKeys] objectAtIndex:[indexPath section]];
    NSArray *contents = [[self sectionContents] objectForKey:key];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];

        UILabel *voornaamLabel = [[[UILabel alloc] initWithFrame:CGRectMake(16, 8, 100, 40)] autorelease];
        voornaamLabel.backgroundColor = [UIColor clearColor];
        //voornaamLabel.textColor = [UIColor whiteColor];
        voornaamLabel.tag = voornaamTag;
        voornaamLabel.font = [UIFont fontWithName:@"Segoe-Semibold" size:19];
        [voornaamLabel setNumberOfLines:1];

        UILabel *tussenvoegselLabel = [[[UILabel alloc] initWithFrame:CGRectMake(16, 8, 100, 40)] autorelease];
        tussenvoegselLabel.backgroundColor = [UIColor clearColor];
        //tussenvoegselLabel.textColor = [UIColor whiteColor];
        tussenvoegselLabel.tag = tussenvoegselTag;
        tussenvoegselLabel.font = [UIFont fontWithName:@"SegoeUI-Light" size:19];
        [tussenvoegselLabel setNumberOfLines:1];

        UILabel *achternaamLabel = [[[UILabel alloc] initWithFrame:CGRectMake(16, 8, 100, 40)] autorelease];
        achternaamLabel.backgroundColor = [UIColor clearColor];
        //achternaamLabel.textColor = [UIColor whiteColor];
        achternaamLabel.tag = achternaamTag;
        achternaamLabel.font = [UIFont fontWithName:@"SegoeUI-Light" size:19];
        [achternaamLabel setNumberOfLines:1];

        [cell.contentView addSubview:voornaamLabel];
        [cell.contentView addSubview:tussenvoegselLabel];
        [cell.contentView addSubview:achternaamLabel];
    }

    NSInteger row = [indexPath row];

    NSDictionary *personDictionary = nil;
    if (tableView == [[self searchDisplayController] searchResultsTableView])
    {
        personDictionary = [[self searchResults] objectAtIndex:row];
    }
    else
    {
        personDictionary = [contents objectAtIndex:[indexPath row]];
    }

    NSString *voornaam = [personDictionary objectForKey:@"voornaam"];
    NSString *tussenvoegsel = [personDictionary objectForKey:@"tussenvoegsel"];
    NSString *achternaam = [personDictionary objectForKey:@"achternaam"];

    UILabel *voornaamLabel = (UILabel *)[[cell contentView] viewWithTag:voornaamTag];
    [voornaamLabel setText:voornaam];
    [voornaamLabel sizeToFit];

    UILabel *tussenvoegselLabel = (UILabel *)[[cell contentView] viewWithTag:tussenvoegselTag];
    [tussenvoegselLabel setFrame:CGRectMake(voornaamLabel.frame.size.width + 21, 8, 100, 40)];
    [tussenvoegselLabel setText:tussenvoegsel];
    [tussenvoegselLabel sizeToFit];

    UILabel *achternaamLabel = (UILabel *)[[cell contentView] viewWithTag:achternaamTag];
    if ([tussenvoegsel length] != 0)
    {
        [achternaamLabel setFrame:CGRectMake(tussenvoegselLabel.frame.origin.x + tussenvoegselLabel.frame.size.width + 5, 8, 100, 40)];
    }
    else
    {
        [achternaamLabel setFrame:CGRectMake(voornaamLabel.frame.size.width + 21, 8, 100, 40)];
    }
    [achternaamLabel setText:achternaam];
    [achternaamLabel sizeToFit];

    return cell;
}
仅供参考:Voornaam表示名字,tussenvoegsel表示第二个名字,achternaam表示姓氏