I have a method that constantly loads new image data from the web. Whenever all data for an image has arrived, it is forwarded to a delegate like this:
NSImage *img = [[NSImage alloc] initWithData:dataDownloadedFromWeb];
if([[self delegate] respondsToSelector:@selector(imageArrived:)]) {
[[self delegate] imageArrived:img];
}
[img release];
In imageArrived:
the image data is assigned to an NSImageView
:
- (void)imageArrived:(NSImage *)img
{
[imageView1 setImage:img];
}
This works nicely, the image is being displayed and updated with every new download cycle. I have profiled my application with Instruments to ensure that there is no leaking - it doesn't show any leaking. However, if I check with Instruments' Activity Monitor, I can see my application grabbing more and more memory with time, roughly increasing by the size of the downloaded images. If I omit [imageView1 setImage:img]
, memory usage stays constant. My question is: how is that happening? Is my code leaking? How does the NSImage
instance within NSImageView
determine when to release its data? Thanks for your answers!