views:

243

answers:

4

Hi Everyone,

We have created an iPhone application which has lot of images in that and we are using facebooker plugin. When we are checking for the memory leaks, it shows lots of memory leaks in foundation framework and CoreGrapics. If anyone will be having any idea about this, please share it with me.

Thanks

A: 

What specifically is leaking? Note that UIImage will cache images so that UIImage doesn't have to keep reloading them if it's called again.

Nimrod
A: 

Core Foundation is not leaking. What leaks is trying to tell you is that an object in Core Foundation leaked because you have not released it, before pointing your variable to other object.

Could you please post some code of the leak so we can help you out?.

OscarMk
A: 

Hi Everyone,

Here is the code that I currently have.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d",indexPath.row];
    static NSInteger CountTag = 1;
    static NSInteger PlaceTag = 2;
    static NSInteger TimeTag = 3;
    NSData* imageData;
    UIImage* imageForData;
    UIImageView* imageView;
    //CellWithId *cell = (CellWithId*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    // if (cell == nil) {
    CellWithId *  cell = [[CellWithId alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
    //}

    CGRect frame;
    frame.origin.x = 5;
    frame.origin.y = 0;
    frame.size.height = 43;
    frame.size.width = 52;

    if ([[planDictionary objectAtIndex:indexPath.row] objectForKey:@"url"]!=[NSNull null]) {
        //This is the line flagged as leaking.
        imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[[planDictionary objectAtIndex:indexPath.row] objectForKey:@"url"]]];
        imageForData = [[UIImage alloc] initWithData:imageData];
        imageView = [[UIImageView alloc] initWithImage:imageForData];
        imageView.frame = frame;
        [cell.contentView addSubview:imageView];
        [imageData release];
        [imageForData release];

    }else {
        //imageForData = [UIImage imageNamed:@"Plans-Default-image.jpg"];
        imageForData = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Plans-Default-image" ofType:@"jpg"]];

        imageView = [[UIImageView alloc] initWithImage:imageForData];
        imageView.frame = frame;
        [cell.contentView addSubview:imageView];
    }

    [imageView release];
    imageData = nil;
    imageForData = nil;

    frame.origin.x = 10;
    cell.accessoryType = UITableViewCellStateShowingDeleteConfirmationMask ;// AccessoryDetailDisclosureButton;
    cell.cellRelatedId = [[[planDictionary objectAtIndex:indexPath.row] objectForKey:@"id"] intValue];
    frame.origin.x = 75; 
    frame.origin.y = 5;
    frame.size.height = 15;
    frame.size.width = 200;

    UILabel *placeLabel = [[UILabel alloc] initWithFrame:frame];
    placeLabel.tag = PlaceTag;
    [cell.contentView addSubview:placeLabel];
    [placeLabel release];

    //frame.origin.y += 18;
//  UILabel *countLabel = [[UILabel alloc] initWithFrame:frame];
//  countLabel.tag = CountTag;
//  [cell.contentView addSubview:countLabel];
//  [countLabel release];

    frame.origin.y += 18;
    UILabel *timeLabel = [[UILabel alloc] initWithFrame:frame];
    timeLabel.tag = TimeTag;
    [cell.contentView addSubview:timeLabel];
    [timeLabel release];

    if ([[[planDictionary objectAtIndex:indexPath.row] objectForKey:@"me_too"] intValue] == 0) {
        frame.origin.x = 35;
        if (selectedButton!=1) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.titleLabel.text = [NSString stringWithFormat:@"%d", cell.cellRelatedId];
            button.titleLabel.hidden = YES;
            [button setFrame:CGRectMake(254.0f, 5.0f, 30.0f, 40.0f)];
            UIImage *img = [UIImage imageNamed:@"metoo.jpeg"];
            [button setImage:img forState:UIControlStateNormal];
            [img release];
            //[button setTitle:@"D" forState:UIControlStateNormal];
            [button addTarget:self action:@selector(meToo:) forControlEvents:UIControlEventTouchUpInside];
            [cell addSubview:button];
        }
    }   

//}

    // Set up the cell...   
    // cell.text = [NSString stringWithFormat:@"State: %@ Capital: %@",[capitals objectAtIndex:indexPath.row],[states objectAtIndex:indexPath.row]];
    //UILabel * placeLabel = (UILabel *) [cell.contentView viewWithTag:PlaceTag];
    //UILabel * countLabel = (UILabel *) [cell.contentView viewWithTag:CountTag];
    //UILabel * timeLabel = (UILabel *) [cell.contentView viewWithTag:TimeTag];
    placeLabel.font = [UIFont boldSystemFontOfSize:15];
    //countLabel.font = [UIFont boldSystemFontOfSize:12];
    timeLabel.font = [UIFont boldSystemFontOfSize:12];
    placeLabel.text = [[planDictionary objectAtIndex:indexPath.row] objectForKey:@"name"];      
    //countLabel.text = [NSString stringWithFormat:@"%@ People", [[[planDictionary objectForKey:@"plans"] objectAtIndex:indexPath.row] objectForKey:@"peopleCount"]];
    timeLabel.text = [[planDictionary  objectAtIndex:indexPath.row] objectForKey:@"planTime"];
    //[placeLabel release];
    //[timeLabel release];
    return cell;
}

The code indicated above is a place where it shows memory leak.

Aashutosh Tiwari
You should edit this into your question instead of posting it as an answer.
Peter Hosey
A: 

In your code snippet you are returning cell without autoreleasing it, from a method that should return an autoreleased object, so that's at least part of the leak you are seeing.

smorgan