Last Updated: February 25, 2016
·
455
· pierrel

layoutView and NSData

Still not sure why (will follow up if I have time) but do not do this:

-(void)layoutSubviews {
  NSData *imageData = [[NSData alloc] initWithContentsOfURL:imageURL];
  UIImage *image = [[UIImage alloc] initWithData:imageData];
  imageData = nil;
  imageView.image = image;
  image = nil;

  // put the imageView somewhere or something
}

That NSData will not be reclaimed as expected (I'm assuming ARC). If a view needs to render a UIImageView from an image file then pull it into memory outside of view rendering code.