Re: NSData being retained?
Re: NSData being retained?
- Subject: Re: NSData being retained?
- From: Jim Ways <email@hidden>
- Date: Thu, 22 Jul 2004 13:20:13 -0700 (PDT)
Ive narrowed it down to a single line of code
//Runs 100% fine
NSData *imageData = [url resourceDataUsingCache:YES];
//increases memory size (leak)
NSData *imageData = [url resourceDataUsingCache:NO];
Am i keeping a list of cache infomation somewhere? Am
i storing aliases to my data somehow?
--- Nick Zitzmann <email@hidden> wrote:
>
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.
>
>
__________________________________
Do you Yahoo!?
Vote for the stars of Yahoo!'s next ad campaign!
http://advision.webevents.yahoo.com/yahoo/votelifeengine/
_______________________________________________
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.