Re: NSURL Tutorial?
Re: NSURL Tutorial?
- Subject: Re: NSURL Tutorial?
- From: "Steven W. Riggins" <email@hidden>
- Date: Sun, 28 Oct 2001 14:14:32 -0800
At 12:02 PM -0800 10/28/01, Jeff LaMarche wrote:
>
There's really not much to it. Here's a method from one of my objects that sounds pretty much like what you're tying to do.
>
>
imageURL is an NSURL IV.
>
imageData is an NSData IV.
>
image is an NSImage IV.
>
>
//----------------------------------------------------------------------
>
-(void)fetchImage
>
//----------------------------------------------------------------------
>
{
>
>
// I can't explain why, but
>
//
>
// [[NSImage alloc] initWithContentsOfURL: imageURL] doesn't
>
//
>
// work, but this does...
>
>
imageData = [NSData dataWithContentsOfURL:imageURL];
>
[imageData retain];
>
image = [[NSImage alloc] initWithData:imageData];
>
>
}
Actually it looks like your way (telling the data to get the data, not the NSURL] does not leak.
NSImage will retain the data, so if you don't need to set the data on another image, you don't need to retain it, right? releasing the NSImage later will release the data (so my tests show)
Steve