简体   繁体   中英

Do i need to release parameter in asynchronous function?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM