Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 什么时候发布imageView的图像?_Iphone_Objective C_Ipad_Ios - Fatal编程技术网

Iphone 什么时候发布imageView的图像?

Iphone 什么时候发布imageView的图像?,iphone,objective-c,ipad,ios,Iphone,Objective C,Ipad,Ios,我创建一个UIImage并设置为imageView的属性,然后释放currentImg, 这些代码中是否存在问题 self.currentContentImv = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, 1024, 768)]; UIImage *currentImg = [[UIImage alloc] initWithContentsOfFile: @"whatever..."]]; self.currentContentIm

我创建一个UIImage并设置为imageView的属性,然后释放currentImg, 这些代码中是否存在问题

self.currentContentImv = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, 1024, 768)];
UIImage *currentImg = [[UIImage alloc] initWithContentsOfFile: @"whatever..."]];
self.currentContentImv.image = currentImg;
[currentImg release];
有时它会崩溃,所以在这种情况下我怎么能写呢

非常感谢

您始终可以使用自动释放


另外,您应该仔细阅读苹果的。

看起来您正在正确地发布当前img。在这种情况下,您可能希望使用static+imageWithContentsOfFile:方法创建UIImage。这将自动将currentImg添加到自动释放池

UIImage *currentImg = [UIImage imageWithContentsOfFile: @"whatever..."];

你确定这段代码会崩溃吗?你能发布一个崩溃的堆栈跟踪吗?它在我朋友的ipad上崩溃了,他告诉我,所以我不确定100%:
UIImage *currentImg = [UIImage imageWithContentsOfFile: @"whatever..."];