English 中文(简体)
排除范围,但使用ARC确定代表。
原标题:Object going out of scope, but delegate is set, using ARC

I m so very sorry for the unclear title, but I can t explain it shortly.

我基本上想知道,如果你使用阿革委,会发生什么情况。

- (void)fooMethod:(NSURLRequest *)fooReq
{
    NSURLConnection *fooConn = [NSURLConnection connectionWithRequest:fooReq delegate:self];
    [fooConn start];
}

因此, f在阴道末的距离就消失了,但我还是会收到呼吁? 换言之,由于没有其他参考资料,它是否会立即获得交易(或像这样的交易),或者由于该代表仍然被搁置,它会留在记忆中处理申请?

最佳回答

Apple果:

- (id)initWithRequest:(NSURLRequest *)request delegate:(id < NSURLConnectionDelegate >)delegate startImmediately:(BOOL)startImmediately

该联系保留了代表。 在连接完成后,该联盟释放了代表。

问题回答

这完全取决于网站后面的<代码>NSURLConnection。 如果保留数值降至零,那么fooConn将仍然是dealloc,届时不会再提出退约。

现在,我认为,在幕后,确实保留了某些地方的物品等级,因此,事实上,你会收到警告。 但是,NSURLConnection 我通常都强烈地提到,它环绕在安全方面。 毕竟,作为你们的呼吁者,你们想要拥有它,而且你希望确保你能够不断追捕代表,而不是听任在任人面前发生的一切。

So, in short, if I were you I d keep a strong reference to it to ensure you won t have to worry.

<代码>ConfooConn是一个当地变量,没有任何所有权限制,因此非洲排雷中心将把它视为强有力的。 因此,ARC将保留通过<条码>连接WithRequest:delegate:退还的价值。 在将其储存成<条码>foxConn时;在退出<条码>fooMethod:时。 排雷中心将发布<代码>fooConn。

That the delegate references the current instance will have no effect on this.

如果希望在<代码>fooMethod:后存在的,一种办法是将其储存成一个实例变量(ARC还精于强力,因此不需要所有权标准)。 如果在班级本身不再是参考,则阿法中心将发布





相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签