adit
adit

Reputation: 33674

debugging AFNetworking memory usage spikes

I have a UICollectionViewCell, in which it has a UIImageView abd I am using the AFNetworking UIImageView category to help me load the images. I've profiled my app and it seems that the memory spike is over the top, it just keeps increasing and increasing after profiling it via Instruments under allocation tools.

enter image description here

I am not sure what happened here and how to fix this. Cells are being reused all the time, but it's just that maybe these images aren't purged from the cache or something. Here's some code of how I am using it, it's pretty straightforward:

  NSURLRequest *imageURLRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:imageURLString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];

  [self.imageView_ setImageWithURLRequest:imageURLRequest placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
        weakSelf.imageView_.image = image;
        weakSelf.imageView_.alpha = 0.0;
        [UIView animateWithDuration:0.3 animations:^{
            weakSelf.imageView_.alpha = 1.0;
        }];

    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {

    }];

If I remove this code to download the image, then the memory footprint is way smaller. Any idea on what might be causing this?

Upvotes: 2

Views: 424

Answers (1)

Victor Ronin
Victor Ronin

Reputation: 23298

Try to wrap it in autoreleasepool and check your memory usage

@autoreleasepool {
    // Code that creates autoreleased objects.
}

Upvotes: 1

Related Questions