2011-10-10 117 views
0

我目前正在開發一個iOS項目,該項目進展良好,但iOS上的整個內存事件 無法正常工作。Objective C,iOS - 收到內存警告

iphone攝像頭記錄一個流。我有一個通過隊列執行的捕獲方法。 相機圖像被轉換爲​​灰度。它運行良好,但過了一段時間後會給出一些 內存警告並關閉應用程序,因爲它的內存不足。

我已經發現了錯誤源到這裏被排出後自動釋放池裏面

CGColorSpaceRef colorSpaceGray = CGColorSpaceCreateDeviceGray(); 
CGContextRef newContextGray = CGBitmapContextCreate(baseAddressGray, width, height, 8, width, colorSpaceGray, kCGImageAlphaNone); 

CGImageRef GrayImage = CGBitmapContextCreateImage(newContextGray); 


UIImage *img= [UIImage imageWithCGImage:GrayImage scale:1.0 orientation:UIImageOrientationRight]; 
[self.imageView performSelectorOnMainThread:@selector(setImage:) withObject:img waitUntilDone:NO]; 



free(baseAddressGray); 
CGColorSpaceRelease(colorSpaceGray); 
CGContextRelease(newContextGray); 


CVPixelBufferUnlockBaseAddress(imageBuffer,0); 

一切謊言。 這是個來源崩潰的線是

CGContextRef newContextGray = CGBitmapContextCreate(baseAddressGray, width, height, 8, width, colorSpaceGray, kCGImageAlphaNone); 

從我的理解應該是這裏沒有記憶問題,因爲

CGColorSpaceRelease(colorSpaceGray); 
CGContextRelease(newContextGray); 

被釋放。

我在這裏做錯了什麼,或缺少什麼?

回答

1

您不會在代碼示例的第4行中發佈GrayImage

+0

非常感謝 - 不再有內存問題了 – chris