2013-02-04 107 views
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?我該如何解決這個問題?

回答

2

檢查數據和圖像上的所有保留/釋放可能會有所幫助。

如果你需要看到保留,發佈和自動釋放出現一個對象使用儀器:在儀器

運行,在設定「記錄的引用計數」關於分配(你必須停止記錄設置的選項)。導致問題代碼運行,停止錄製,在那裏搜索感興趣的ivar,深入瞭解,您將能夠看到所有保留,發佈和autoreleases發生。

enter image description here