Objective C - NSImageView、NSImage、NSBitmapImage 代表对象生命周期?
我构建了一个视频查看器,它是一个 Safari 插件,可以显示来自网络设备的视频。查看器读取位图图像,准备它们,并将它们设置在 NSImageView 对象上,如下所示:
NSBitmapImage *bmImg = [[NSBitmapImage alloc] initWithBitmapDataPlanes: 。 。 .]
NSImage *img = [[NSImage alloc] init];
[img addRepresentation:bmImg];
图像通过主线程上的“setImage”添加到 NSImageView 中。视频显示正常。
我的问题是,通过“setImage”设置下一个图像的行为是否应该导致前一个图像及其关联的位图图像被释放并随后释放?
我需要自己对分配的映像执行 [img release] 吗?
我是否需要从 img 中删除图像代表并释放它?
提前致谢。
I've built a video viewer that is a Safari plugin that displays video from networked devices. The viewer reads bitmap images, prepares them, and sets them on the NSImageView object as follows:
NSBitmapImage *bmImg = [[NSBitmapImage alloc] initWithBitmapDataPlanes: . . .]
NSImage *img = [[NSImage alloc] init];
[img addRepresentation:bmImg];
The image is added to the NSImageView via "setImage" on the main thread. The video displays fine.
My question is, shouldn't the act of setting the next image via "setImage" cause the prior image and its associated bitmap image to be released and subsequently freed?
Do I need to perform the [img release] on the alloc'd image myself?
Do I need to remove the image rep from the img and release it also?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你需要实际去阅读 Cocoa 内存管理指南。它将回答您所有的问题。
You need to actually go and read the Cocoa memory management guide. It will answer all your questions.
实际上,在发布到这里之前,我确实阅读了 Cocoa 内存管理指南。这不是一个非常明显的解决方案,尽管当我再次阅读该指南时确实有所帮助。
解决方案是在将 NSImage 和 NSBitmapImageRep 实例发送到 NSImageView 上的“setImage”后释放它们。
I actually did read the Cocoa memory management guide prior to posting here. It was not a very obvious solution though the guide did help once I read it again.
The solution was to release the NSImage and NSBitmapImageRep instances after sending it to "setImage" on NSImageView.