Re: NSData being retained?
Re: NSData being retained?
- Subject: Re: NSData being retained?
- From: Nick Zitzmann <email@hidden>
- Date: Thu, 22 Jul 2004 13:58:50 -0600
On Jul 22, 2004, at 12:50 PM, Jim Ways wrote:
NSAutoreleasePool *mainPool = [[NSAutoreleasePool
alloc] init];
Here you are creating an autorelease pool.
while(looping)
{
NSAutoreleasePool *localPool = [[NSAutoreleasePool
alloc] init];
Here you are creating a second autorelease pool.
NSString *urlString = a_string_i_got_from_somewhere
NSURL* aUrl = [NSURL URLWithString:urlString];
Here you are creating an autoreleased NSURL with the string urlString.
aUrl is in the localPool autorelease pool, and will be released when
localPool is released.
NSData *data = [aUrl resourceDataUsingCache:NO];
Here you are creating an autoreleased NSData through the aURL object.
data is in the localPool autorelease pool, and will be released when
localPool is released.
[aUrl release]; //with or without this line i get it
Here you are crashing the program by releasing an autoreleased object.
[localPool release];
}
Had your program not crashed, this line would cause aUrl and data to be
immediately released. Had your program not crashed, any attempt to use
aUrl or data after this point would cause a crash, because you would be
trying to access deallocated objects.
[mainPool release];
This line does nothing because you didn't put anything into mainPool's
autorelease pool, even if your program hadn't crashed above.
As others have suggested, I think you ought to read up on Cocoa memory
management. Others have given you URLs to read.
Nick Zitzmann
<
http://www.chronosnet.com/>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.