0

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?

Scyllar
  • 43
  • 5

1 Answers1

1

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.

Kurt Revis
  • 27,695
  • 5
  • 68
  • 74
  • At first, thanks for the explanation...but when i get the retainCount of the request, it returns 1, same with when you alloc,int. how do you explain that? – Scyllar Jan 10 '13 at 07:44
  • 2
    [retainCount is useless](http://www.friday.com/bbum/2011/12/18/retaincount-is-useless/). – sosborn Jan 10 '13 at 07:49