Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get rid of massive Memory leak with blurred image in uitableview cell
    primarykey
    data
    text
    <p>Somehow when I scroll to the bottom of my table (96 items only) I get 1 gb of memory usage (it increase for every cell that gets created. I have a table that has an image with a blurred image in front of it that is using a cropped version of the original image with text then on top of that. Pretty simple. I'm using the apple provided sample code for blurring images available here: <a href="https://github.com/iGriever/TWSReleaseNotesView/blob/master/TWSReleaseNotesView/UIImage%2BImageEffects.m" rel="nofollow noreferrer">https://github.com/iGriever/TWSReleaseNotesView/blob/master/TWSReleaseNotesView/UIImage%2BImageEffects.m</a></p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"itemCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSDictionary *foodItem = [self.foodItems objectAtIndex:indexPath.row]; // Set up the image view UIImageView *imageView = (UIImageView *)[cell viewWithTag:1]; UIImage *foodImage = [UIImage imageNamed:[foodItem objectForKey:FOOD_IMAGE_FILE_KEY]]; [imageView setImage:foodImage]; [imageView setContentMode:UIViewContentModeScaleAspectFill]; // Set up the label UILabel *labelView = (UILabel *)[cell viewWithTag:2]; [labelView setFont:[UIFont flatFontOfSize:20.0]]; labelView.text = @"Blah"; // Set up the image view UIImageView *blurredView = (UIImageView *)[cell viewWithTag:3]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ UIImage *blurredImage = [[self cropForBlur:foodImage] applyBlurWithRadius:4 tintColor:[UIColor colorWithWhite:1.0 alpha:0.2] saturationDeltaFactor:1.2 maskImage:nil]; dispatch_sync(dispatch_get_main_queue(), ^{ blurredView.image = blurredImage; }); }); return cell; </code></pre> <p>}</p> <p>*Note: I know it is most likely the blur (as opposed to my cropping) as it only happens when I do the blur. Also it's nothing to do with the async dispatch stuff as it still happens if I don't do that.</p> <p>Yes I'm using ARC. Yes I'm using storyboards.</p> <p>Here's cropForBlur:</p> <pre><code>- (UIImage *)cropForBlur:(UIImage *)originalImage { CGSize size = [originalImage size]; int startCroppingPosition = 100; if (size.height &gt; size.width) { startCroppingPosition = size.height/2 + ((size.width / 320) * 45); } else { startCroppingPosition = size.height/2 + ((size.width / 320) * 45); } // WTF: Don't forget that the CGImageCreateWithImageInRect believes that // the image is 180 rotated, so x and y are inverted, same for height and width. CGRect cropRect = CGRectMake(0, startCroppingPosition, size.width, ((size.width/320) * 35)); CGImageRef imageRef = CGImageCreateWithImageInRect([originalImage CGImage], cropRect); UIImage *newImage = [UIImage imageWithCGImage:imageRef scale:(size.width/160) orientation:originalImage.imageOrientation]; CGImageRelease(imageRef); return newImage; } </code></pre> <p>I've also tried looking in Instruments but it will show that I'm using heaps of memory in total but the big chunks of memory don't show up in the breakdown. Weird.</p> <p>Here's the bit that's saying I am using heaps of memory in the left bar. <img src="https://i.stack.imgur.com/HiQfX.png" alt="enter image description here"></p> <p>Here's the allocations bit in Instruments. I don't see how they could match up. I haven't got zombies on or anything (unless there's somewhere other that in edit scheme to change that). <img src="https://i.stack.imgur.com/xeJ69.png" alt="enter image description here"></p> <p>Here's the leaks Instruments view after scrolling down a bit. Doesn't seem to show any real leaks :S So confused. <img src="https://i.stack.imgur.com/HM0SN.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload