When is the autorelease pool triggered

后端 未结 2 1192
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 14:11

i have used autorelease throughout my app and would like to understand the behavior of the autorelease method. When is the default autorelease pool drained? is it based on a

2条回答
  •  一向
    一向 (楼主)
    2021-01-13 14:51

    It is drained whenever the current run-loop finishes. That is when your method and the method calling your method and the method calling that method and so on is all done.

    From the documentation:

    The Application Kit creates an autorelease pool on the main thread at the beginning of every cycle of the event loop, and drains it at the end, thereby releasing any autoreleased objects generated while processing an event

提交回复
热议问题