gpt4 book ai didi

ios - 预定的定时器会自动释放吗

转载 作者:搜寻专家 更新时间:2023-11-01 06:21:45 26 4
gpt4 key购买 nike

我正在使用以下 NSTimer 类方法:

NSTimer.scheduledTimerWithTimeInterval(
3,
target: self,
selector: Selector("setWaitThreeSecondsFalse"),
userInfo: nil,
repeats: false
)

返回的计时器在选择器运行后是否被释放?还是我必须明确地使计时器无效?

最佳答案

来自 Apple 文档:

Timers work in conjunction with run loops. To use a timer effectively, you should be aware of how run loops operate—see NSRunLoop and Threading Programming Guide. Note in particular that run loops maintain strong references to their timers, so you don’t have to maintain your own strong reference to a timer after you have added it to a run loop.

由于运行循环持有对 NSTimer 对象的字符串引用,您必须使 NSTimer 无效才能将其从运行循环中移除。

编辑这显然对重复计时器有效。正如 rmaddy 指出的那样,非重复会自动失效!

关于ios - 预定的定时器会自动释放吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32793187/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com