I had the same problem. My problem, apparently, came from something other than the SDWebImage cache, but since it was contributing to memory accumulation, the first thing I, however, concluded was that the cache could be the cause of my problem. But this is not so. You may have the same problem. Keep in mind that I am using ARC.
- Run the profiler with the
Leaks template and check the allocation of your own classes in the Allocation Summary . - Immerse yourself in them and check how they are distributed if there are leaks. Keep in mind that the leak does not appear in the
Leaks tool because you are using ARC. So the tools might think that everything is going fine, but somewhere there might be a leak. Having plunged into the distribution of your classes, you can understand what is going wrong. - Keep in mind that retention / release count information is provided only when using the
Leaks template, and not when using the Allocations template.
My problem was that I referenced the instance and self variables directly from within the blocks, without reassigning them to __weak variables. When self is used inside a block, it will be automatically saved by ARC and sometimes will never be released. Weak recommendation prevents this.
For example, this is not true:
[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardDidShowNotification object:nil queue:nil usingBlock:^(NSNotification *note) { [self.view setContentOffset:CGPointMake(0.0, kKeyboardOffset) animated:YES]; }];
You must call self using the __weak link, for example:
__weak YourViewControllerClass *weakSelf = self; [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardDidShowNotification object:nil queue:nil usingBlock:^(NSNotification *note) { [weakSelf.view setContentOffset:CGPointMake(0.0, kKeyboardOffset) animated:YES]; }];
Since my application uses many blocks, I had a ton of leaks, the Leaks tool could not detect. When I fixed them, the memory issue disappeared.
Hope this helps.
thijsai
source share