1
我在我的應用程序中遇到內存問題。異步NSData仍然在沒有緩存的內存中
當我啓動它,文檔和我的應用程序的數據是212KB
我推ViewControler A之後,我在一個TableView中加載圖像異步的LOTE從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];
而且完美的工作!此時,文檔和數據10MB
但是在彈出ViewController並在NSLog中看到調用ViewController的dealloc後,我的應用程序仍然有10MB。我不會緩存圖像。
爲什麼還要10MB?我該如何解決這個問題?