UIImageView memory leak using ARC

In DetailViewController.h: @property (weak, nonatomic) IBOutlet UIImageView *recipeImage;

In DetailViewController.m

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.recipeTitle.text = rec.title;
    self.recipeDetail.text = rec.details;
    NSString *fileName = [NSString stringWithFormat: @"%@/%@", [[NSBundle mainBundle] resourcePath], rec.image];
    UIImage *tmp = [[UIImage alloc] initWithContentsOfFile: fileName];
    self.recipeImage.image = tmp;
    NSLog(@"%@", rec.image);
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    recipeTitle = nil;
    recipeDetail = nil;
    recipeImage = nil;
    rec = nil;
}

For some reason, recipeImage UIImageView IBOutlet causes a memory leak

enter image description here

enter image description here

+3
source share
1 answer

Hm. I was a little surprised by this, since I do not see any obvious leaks in your code. So I did a small test project (Xcode 4.3.2, iPhone simulator 5.1, ARC, storyboards) to see if I can reproduce your problem and run it through the profiler, and there are no leaks.

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    self.label1.text = @"Line 1";
    self.label2.text = @"Line 2";

    NSString *filename = [NSString stringWithFormat: @"%@/%@", [[NSBundle mainBundle] resourcePath], @"IMG_0999.PNG"];

    UIImage *image = [[UIImage alloc] initWithContentsOfFile:filename];

    self.image1.image = image;
}

and, like you, I used weak properties:

@property (weak, nonatomic) IBOutlet UILabel *label1;
@property (weak, nonatomic) IBOutlet UILabel *label2;
@property (weak, nonatomic) IBOutlet UIImageView *image1;

I don't think the API goes beyond leaks (I definitely saw some leaks in the Twitter API, for example), but I can't reproduce your problem.

, ( ): -, - PNG? , , . , , PNG . , , , , , , . -, - ? , , malloc, , , , , .

, , . , .

Update:

, PNG, , iOS ( - iOS, PNG). , , , - , iOS . http://bugreport.apple.com. , PNG . , .

+2

All Articles