performSelector:withObject:及其保留行为 [英] performSelector:withObject: and its retain behavior

查看:253
本文介绍了performSelector:withObject:及其保留行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是SO中已经解决的问题,但我在任何地方的Apple文档中找不到该问题.你能指出我正确的方向吗?

This is an already answer question within SO but I cannot find it in the Apple documentation anywhere. Could you point me in the right direction?

在以下主题内

我是否必须保留一个对象,然后再将其传递给-performSelector:withObject:afterDelay :?

对performSelector:withObject:afterDelay:inModes的保留计数的影响

是调用performSelector:withObject:afterDelay的对象被NSRunLoop保留?

默认行为似乎如下:它保留了接收方和参数.

我正在使用以下代码

[[self delegate] performSelector:@selector(tryToSendStoreData:) withObject:userData];

其中userData是自动释放的对象.

where userData is an autoreleased oject.

记录保留计数(我知道这样做可能无效),以增量方式传递的数据将保留计数.在委托上调用该方法时,保留计数不等于1.

Logging the retain count (I know that it could be not valid to do it) the data passed in increments its retain count. When the method is invoked on the delegate, the retain count is not equal to one.

所以,我的问题是:我需要执行一些内存管理以避免泄漏吗?还是我必须信任Apple的东西?在这里,我说的是不可知论者,因为我找不到合适的文档.

So, my question is: do I need to perform some memory management to avoid leaks or do I have to trust on Apple stuff? Here I'm speaking as an agnostic since I cannot find the right docs.

谢谢.

推荐答案

您在文档中查看的是错误的函数.

You are looking at the wrong function in the documentation.

保留

performSelector:withObject:afterDelay:和类似函数( with afterDelay)保留了接收方和参数,因为稍后执行

performSelector:withObject:afterDelay: and similar functions (with afterDelay) retain the receiver and arguments, because the execute later

无保留

performSelector:withObject:和类似功能( afterDelay)不保留任何内容,因为它们只是直接调用该功能.

performSelector:withObject: and similar functions (without afterDelay) do not retain anything, since they just call the function directly.

[[self delegate] performSelector:@selector(tryToSendStoreData:) withObject:userData];

做与

[[self delegate] tryToSendStoreData:userData];

这篇关于performSelector:withObject:及其保留行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆