UIImage CGImage:发送到已释放实例的消息

发布于 2024-09-25 19:48:45 字数 787 浏览 2 评论 0原文

以下是我的代码片段:

在 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扬花落满肩 2024-10-02 19:48:45

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文