UIImage CGImage:发送到已释放实例的消息
以下是我的代码片段:
在 .h 文件中:
@property (nonatomic, retain) UIImage *photo;
@property (nonatomic, retain) NSData *photoData;
在 .m 文件中:
@synthesize photo;
@synthesize photoData;
...
photo = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; {*}
...
NSLog(@"b1");
self.photoData = UIImagePNGRepresentation(self.photo);
NSLog(@"b2");
以下是我在控制台中看到的日志:
b1
*** -[UIImage CGImage]: message sent to deallocated instance 0x583b1d0
如何防止此“消息发送到已释放实例”问题?我对此很陌生,所以我真的很感激一些关于为什么会发生这种情况的背景? (指向一些文档的指针也很棒)
谢谢
更新: * 错误发生在此处。感谢 codelark 指出了这一点。如果将此行更改为以下内容,则不会发生该错误。
photo = [[info objectForKey:@"UIImagePickerControllerOriginalImage"] retain];
Following is a snippet of my code:
in the .h file:
@property (nonatomic, retain) UIImage *photo;
@property (nonatomic, retain) NSData *photoData;
in the .m file:
@synthesize photo;
@synthesize photoData;
...
photo = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; {*}
...
NSLog(@"b1");
self.photoData = UIImagePNGRepresentation(self.photo);
NSLog(@"b2");
Here are the logs that I see in the console:
b1
*** -[UIImage CGImage]: message sent to deallocated instance 0x583b1d0
How can i prevent this "message sent to deallocated instance" problem? I am very new to this, so I'd really appreciate some background into why this is happening? (A pointer to some docs would be great too)
Thanks
UPDATE:
* The error occurs here. Thanks to codelark for pointing that out. If this line gets changed to the following, the error will not happen.
photo = [[info objectForKey:@"UIImagePickerControllerOriginalImage"] retain];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
0x583b1d0 可能是相关对象的地址(self 的值)。您可以使用 NSLog 或 printf 与 %p 来打印它。
PK
0x583b1d0 is likely the address of object in question (the value of self). You can use NSLog or printf with %p to print it.
PK