2013-11-03 29 views
7

所以我讓我的應用程序採取了截屏,並將其保存到相冊與下面的代碼...核芯顯卡柵格數據不會從內存中釋放

- (void) save { 
     UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0); 
     [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
     UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 
     UIImageWriteToSavedPhotosAlbum(theImage,nil,NULL,NULL); 
     NSData*theImageData=UIImageJPEGRepresentation(theImage, 1.0); 
     [theImageData writeToFile:@"image.jpeg" atomically:YES]; 
    } 

我怎樣才能釋放內存由擁有屏幕截圖柵格數據的Core Graphics分配?

我的項目使用ARC進行內存管理。在測試應用程序如何分配內存時,我注意到內存在拍攝屏幕後未被釋放,導致應用程序隨着時間的推移變得緩慢。樂器中的「分配彙總」告訴我數據類別是「CG柵格數據」,而負責的調用者是「CGDataProviderCreatWithCopyOfData」。

CFRelease()中有解決方案嗎? ?

我的第一應用,所以我很小白,我已經在互聯網一看就嘗試沒有運氣解決問題...

回答

0

你可以嘗試包裝你的方法的內容轉換成一個@autorelease區塊。

@autoreleasepool { 
... 
} 
+0

你的意思是@autoreleasepool? – Yariv

+0

確實,對不起。 – Mundi

+0

@Mundi無法正常工作。 –