Iphone 什么时候发布imageView的图像?
我创建一个UIImage并设置为imageView的属性,然后释放currentImg, 这些代码中是否存在问题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
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..."];