views:

364

answers:

2

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.

A: 

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

Mike Abdullah
A: 

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.

snapdev