开发者

What happens to tasks in dispatch queues when an app enters inactive/background/suspended states in iOS?

开发者_StackOverflow社区I've been scouring Apple's documentation on application states and Grand Central Dispatch, but I haven't found a good answer to this question.

According to Apple's documentation, on iOS 4.0:

The application is in the background but is not executing code. The system moves an application to this state automatically and at appropriate times. While suspended, an application is essentially freeze-dried in its current state and does not execute any code. During low-memory conditions, the system may purge suspended applications without notice to make more space for the foreground application.

So assuming the system does not purge a suspended application (suspended -> not running transition), what happens to tasks that are currently executing in a dispatch queue? The phrase "Essentially freeze-dried" leaves much to be desired - exactly what is freeze dried?

My interpretation is whichever GCD queues an app is using at time of suspension will need to be reinstated when the app transitions back to active state; under this interpretation, the tasks existing in pre-suspension GCD queues would disappear. Is my interpretation correct?


When an app is suspended, the entire process is frozen. You can count on the process resuming as if nothing happened at all once it is resumed. Your apps's GCD logical queues don't go away, they remain as they were in memory. And the threads GCD had created in your process to service your queues are resumed in place as if nothing happened as well.

So your interpretation is incorrect: tasks existing in pre-suspension GCD queues do not disappear upon resumption. They never went away; they were only paused.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜