开发者

Objective C - NSImageView, NSImage, NSBitmapImage rep object lifecycle?

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开发者_StackOverflow 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.


You need to actually go and read the Cocoa memory management guide. It will answer all your questions.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜