有没有理由保留计划的NSTimer如果你不需要使它无效
问题说明
我要回到一些crufty代码整理它,我看到我一直保留从 scheduledTimerWithTimeInterval返回的NSTimers:target:selector:userInfo:repeats:
并将它们存储在字段中,然后在触发时释放和取消字段。在某些情况下,我使用计时器向其发送无效的消息 - 但在很多情况下不是。
I'm going back over some crufty code to tidy it up and I see I've been retaining NSTimers returned from scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:
and storing them in a field - then releasing and nulling the field when it fires. In some cases I use the timer to send an invalidate message to it later - but in many cases not.
在最近的代码中,我通常只是计划定时器,它。我知道构造函数方法是自动释放,并且定时器在运行循环保持,而它是活动的 - 所以我没有看到任何问题。
In more recent code I usually just schedule the timer and forget about it. I understand that the constructor method is autoreleasing and the timer is retained by the run loop while it is active - so I don't see any issue with this.
只是为了加深我的理解 - 是否有任何其他原因,我应该坚持我的计时器,或者是我现在正在做的接受的成语?
So, just to round out my understanding - is there any other reason I should be holding on to my timers, or is what I am doing now the accepted idiom?
这是所有在iPhone代码的上下文中,但我不相信这是iPhone的具体。
This is all in the context of iPhone code, but I don't believe this is iPhone specific.
正确答案
保留,我 - 这是拥有定时器的运行循环,而不是我。如果你看到我的意思。
I just let the run loop handle the retention, myself - it's the run loop that owns the timer and not me. If you see what I mean.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcakffa
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20