I have a problem with memory in my app.
When I start it, the Documents and Data of my app is 212KB
After I push the ViewControler A, I load in a TableView a lote of images async from Facebook:
UIButton *friendPhoto = [UIButton buttonWithType:UIButtonTypeCustom];
[friendPhoto addTarget:self
action:@selector(friendPhotoWasClicked:)
forControlEvents:UIControlEventTouchUpInside];
[friendPhoto setFrame:CGRectMake(x, photoMargeY, photoSize, photoSize)];
// GET IMAGE ASYNC
NSURL *imageURL = [NSURL URLWithString:faceURL];
[friendPhoto setImage:[UIImage imageNamed:@"default"]
forState:UIControlStateNormal];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSData *data = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
[friendPhoto setImage:image
forState:UIControlStateNormal];
});
});
//}
[cell.contentView addSubview:friendPhoto];
And work perfectly! At this point, the Documents and Data 10MB
But after pop the ViewController and see in NSLog that call dealloc for ViewController, my app still with 10MB. I’m not make cache of the images.
Why still with 10MB? How can I resolve that?
Inspecting all retains/releases on the data and images might help.
If you need to see where retains, releases and autoreleases occur for an object use instruments:
Run in instruments, in Allocations set “Record reference counts” on on (you have to stop recording to set the option). Cause the problem code to run, stop recording, search for there ivar of interest, drill down and you will be able to see where all retains, releases and autoreleases occurred.