Skip navigation.
 
mlDownloading image from web and memory usage questions
FROM : John Tsombakos
DATE : Fri Jan 24 22:05:09 2003

  Given this routine that is in the action method of a button and an
ImageView in a window:

  NSString* string = @"http://www.rccl.com/rc/image/vywebcam.jpg";

    if (string) {
        NSURL* url = [NSURL URLWithString:string];
        if (url) {
            NSData *imageData = [url resourceDataUsingCache:NO];
            if (imageData) {
                NSImage* image = [[NSImage alloc]
initWithData:imageData]; // ** 1
                if (image) {
                    [voyagerImage setImage:image];
                    [image release];
                   // [imageData release];    // ** 2
                } else {
                    NSLog(@"couldn't init image from imageData
%@\nLoaded from %@\nReferenced by %@\nwith url %@", imageData, url,
string);
                }
            } else {
                NSLog(@"can't init imageData from url %@\n with string
%@", url, string);
            }
        } else {
            NSLog(@"can't init url from string %@", url);
        }
    } else {
        NSLog(@"couldn't get a string from sender %@", sender);
    }

The first question/problem - the image that is being downloaded is from
a web cam and it seems that sometimes the full image is not available.
What happens is on the line marked **1 when it gets to it, if the image
isn't complete, a message is generated in the Console (or on the
console in Project Builder) - "Application transferred too few
scanlines". Is there any way to detect that it failed to load? That
message is displayed and nothing is displayed.

Second question deals with retain and release. I originally did not
have the [image release] statement in there and while watching 'top', I
could see that memory was being taken up and not released every time I
clicked the button (assuming the image actually loaded). I added the
release and the memory stopped being eaten up. I then figured I also
needed to release the imageData object (marked **2). When that's in
there, the app crashes. My question is why don't I need to release
that? I understand the concept of the release and retain, but just
can't figure out which routines return something that I need to
release. Any hints or help would be nice.

Thanks!

Related mailsAuthorDate
mlDownloading image from web and memory usage questions John Tsombakos Jan 24, 22:05
mlRe: Downloading image from web and memory usage questions Shawn Erickson Jan 24, 22:54
mlRe: Downloading image from web and memory usage questions John Tsombakos Jan 24, 23:46
mlRe: Downloading image from web and memory usage questions Jeremy Erwin Jan 25, 00:23
mlRe: Downloading image from web and memory usage questions James J. Merkel Jan 25, 11:45
mlRe: Downloading image from web and memory usage questions Shawn Erickson Jan 25, 12:43
mlRe: Downloading image from web and memory usage questions Shawn Erickson Jan 25, 13:01
mlRe: Downloading image from web and memory usage questions James J. Merkel Jan 25, 13:36
mlRe: Downloading image from web and memory usage questions Jeremy Erwin Jan 25, 13:42
mlRe: Downloading image from web and memory usage questions Shawn Erickson Jan 26, 08:56