Question

I've googled a lot for this, but get no clue for it.

First of all, i'm not using ARC.

let's say i am calling a asynchronous function, and passing a pointer A to it, initialially i thought, okay, let's pass a autoreleased pointer A to it, the async function will release A after it finished its operation. but seems it won't work.

NSURLRequest *request = [[[NSURLRequest requestWithURL:[NSURL URLWithString:@"someurl"]] autorelease];
[webView loadRequest:request];

Then there's a EXC_BAD_ACCESS error coming in, if i remove the autorelease, then it goes fine.

anyone knows about this?

Was it helpful?

Solution

Please read the basic memory management rules again.

You didn't create the NSURLRequest using a method containing the words “alloc”, “new”, “copy”, or “mutableCopy”, so you don't own it, so you shouldn't release it.

Also, you are not "calling an asynchronous function". When you call [webView loadRequest:], the method call happens immediately and synchronously. That method starts some asynchronous work behind the scenes, which completes later on -- but that doesn't affect the way that you call the method in the first place, or the memory management for its arguments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top