IPhone: UITableView flows like a Titanic!

This is the code of my cellForRowAtIndexPath of my UITableView

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *identificadorNormal = @"Normal";

        UITableViewCell *cell;

        cell = [tableView dequeueReusableCellWithIdentifier:identificadorNormal];

        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                               reuseIdentifier:identificadorNormal] autorelease];

            UILabel * myText = [[[UILabel alloc] initWithFrame:CGRectMake(5.0, 54.0, 225, 18)] autorelease];
            [myText setTextAlignment:UITextAlignmentLeft];
            [myText setBackgroundColor:[UIColor whiteColor ]];
            [myText setClipsToBounds:YES];
            [myText setFont:[UIFont systemFontOfSize:14.0]];
            [myText setTextColor:[UIColor blackColor]];
            [myText setAlpha:0.6];
            [myText setTag: 1];
            [cell addSubview:myText];

            UILabel * labelFRE = [[[UILabel alloc] initWithFrame:CGRectMake(235.0, 54.0, 80, 18)] autorelease];
            [labelFRE setTextAlignment:UITextAlignmentCenter];
            [labelFRE setBackgroundColor:[UIColor greenColor ]];
            [labelFRE setClipsToBounds:YES];
            [labelFRE setFont:[UIFont boldSystemFontOfSize:14.0]];
            [labelFRE setTextColor:[UIColor blackColor]];
            [labelFRE setAlpha:0.75];
            [labelFRE setTag: 2];
            [cell addSubview:labelFRE];
        }

        cell.imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] 
            pathForResource:[NSString stringWithFormat: @"table%d", indexPath.row] ofType:@"jpg"]];     
        NSString * preffix = [NSString stringWithFormat: @"grat%d", indexPath.row];

        UILabel *myText2 = (UILabel*)[cell viewWithTag:1];
        [myText2 setText:NSLocalizedString(preffix, @"")];

        UILabel *labelFRE2 = (UILabel*)[cell viewWithTag:2];
        [labelFRE2 setText:NSLocalizedString(@"frKey", @"")];       
        return cell;
}

It seeps like hell. . Each time I look at the table, more leaks are added to the list of tools.

Can you guys understand why?

Thanks for any help.

EDIT

After the first round of comments, I changed the previous code to this

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identificadorNormal = @"Normal";

    UITableViewCell *cell;

    cell = [tableView dequeueReusableCellWithIdentifier: identificadorNormal];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
            reuseIdentifier:identificadorNormal] autorelease];

        UILabel * myText = [[UILabel alloc] initWithFrame:CGRectMake(5.0, 54.0, 225, 18)];
        [myText setTextAlignment:UITextAlignmentLeft];
        [myText setBackgroundColor:[UIColor whiteColor ]];
        [myText setClipsToBounds:YES];
        [myText setFont:[UIFont systemFontOfSize:14.0]];
        [myText setTextColor:[UIColor blackColor]];
        [myText setAlpha:0.6];
        [myText setTag: 1];
        [cell addSubview:myText];
            [myText release];

        UILabel * labelFRE = [[UILabel alloc] initWithFrame:CGRectMake(235.0, 54.0, 80, 18)];
        [labelFRE setTextAlignment:UITextAlignmentCenter];
        [labelFRE setBackgroundColor:[UIColor greenColor ]];
        [labelFRE setClipsToBounds:YES];
        [labelFRE setFont:[UIFont boldSystemFontOfSize:14.0]];
        [labelFRE setTextColor:[UIColor blackColor]];
        [labelFRE setAlpha:0.75];
        [labelFRE setTag: 2];
        [cell addSubview:labelFRE];
            [labelFRE release];
    }

    cell.imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] 
        pathForResource:[NSString stringWithFormat: @"table%d", indexPath.row] ofType:@"jpg"]];     
    NSString * preffix = [NSString stringWithFormat: @"grat%d", indexPath.row];

    UILabel *myText2 = (UILabel*)[cell viewWithTag:1];
    [myText2 setText:NSLocalizedString(preffix, @"")];

    UILabel *labelFRE2 = (UILabel*)[cell viewWithTag:2];
    [labelFRE2 setText:NSLocalizedString(@"frKey", @"")];       
    return cell;
}

leaks continue. No changes.

+3
source share
6 answers

Looking at http://imgur.com/XPRYF doesnโ€™t look like your leak. Is it on the device or in the simulator?

GSEvents, 3.0.

NSAutoreleaseFreedObjectCheckEnabled, NSZombieEnabled NSDebugEnabled, - , .

, , - , - , , .

+2

autorelease , , , , . , (, ).

, , autorelease

myThing = [[Obj alloc] initWithWhatever];
[myThing doStuff];
[cell addSubview:myThing];
[myThing release];
+2

, identificadorNormal @"normal" ? @"normal", , identificadorNormal. , @"normal", , tableview .

0

, , UIImage ?

+imageNamed ? UIImage ( +imageWithContentsOfFile:). , , , , .

NSString *imageName = [NSString stringWithFormat: @"table%d.jpg", indexPath.row];
cell.imageView.image = [UIImage imageNamed:imageName];         
0

, , , (iPhone 3GS, iPod Touch 2G).

, , , Apple, .

0

, . - , . ( , ), , , -o -o1. , .

0
source

Source: https://habr.com/ru/post/1721241/


All Articles