2014-10-16 32 views
1

imageUIImage的實例。第一行執行沒有問題,但第二行在運行時給出EXC_BAD_ACCESS錯誤。EXC_BAD_ACCESS訪問UIImage的大小屬性

NSLog(@"SCALE: %f", image.scale); 
NSLog(@"TEST: %@", NSStringFromCGSize(image.size)); 

我可以通過鼠標懸停儘管它查看在Xcode size屬性的值。

enter image description here

能否請你幫我瞭解什麼是錯的和/或什麼我可能會丟失?

測試的設備上,並在模擬器運行iOS 8

UPD:這是我如何創建圖像:

ALAssetRepresentation *rep = [asset defaultRepresentation]; 
CGFloat scale = 1.0f; 

CGImageRef imageRef = [rep fullResolutionImage]; 
UIImage *image = [UIImage imageWithCGImage:imageRef scale:scale orientation:(UIImageOrientation)rep.orientation]; 

CGImageRelease(imageRef); 

我只是試圖刪除最後一行CGImageRelease(imageRef);,它似乎解決問題。但是我確實需要發佈CGImageRef,因爲我在循環中加載了非常大的照片,並且佔用了大量內存。

+0

對我來說工作正常,只需使用UIImage * image = [[UIImage alloc] init]檢查您的代碼,就可以爲我們提供完整的代碼和圖像實例初始化 – Injectios 2014-10-16 15:01:36

回答

1

所以,我想通了。問題是我發佈了一個我沒有的CGImageRef。

CGImageRef imageRef = [rep fullResolutionImage]; 

如果通過調用fullResolutionImage得到CGImageRef,你沒有擁有它。因此,你不需要自己釋放它。

CGImageRelease(imageRef); 

刪除最後一行解決了我的問題。