【问题标题】:IOS: property and deallocIOS:属性和dealloc
【发布时间】:2013-06-11 10:16:45
【问题描述】:

我有一个愚蠢的问题,在我的代码中:

在.h中

@property (nonatomic, retain) UIImage *currentImage;

英寸米

@syntesyze currentImage;

然后在我的课堂上我使用“self.currentImage”...

在 dealloc 中我尝试做:

[self.currentImage release] or self.currentImage = nil

但是我的应用程序崩溃了,问题是“消息发送到已释放的实例”,为什么?我在 .h 中有一个保留,有什么问题?

【问题讨论】:

  • 请仅使用 [currentImage release] 尝试;
  • @syntesyze 是这里的错字还是在您的代码中?
  • 我们在 viewDidUnload 方法中执行 self.currentImage = nil 。虽然你的代码看起来不错。我会建议你启用 NSZombies 来解决与内存相关的问题。它会告诉你对象在哪里被释放

标签: ios properties retain


【解决方案1】:

从 self.currentImage 中删除自我。

[currentImage release];
currentImage = nil;

【讨论】:

  • 我使用此图像从相机拍摄图像,如果我不使用 sel.currentImage 我的应用程序崩溃并且我收到此消息“-[UIImage retain]: message sent to deallocated instance 0x253b1470”
  • 我用 self.currentImage = nil in viewdidunload 解决了我的问题
【解决方案2】:

我用

解决了我的问题
self.currentImage = nil;

viewDidUnload 方法中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 2011-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多