@autoreleasepool in loop or loop in @autoreleasepool?

前端 未结 6 593
遇见更好的自我
遇见更好的自我 2020-12-30 23:22

It\'s a good practice to put lots of autoreleased object in an autoreleasepool at loop action. I found someone put the @autoreleasepool in loop but others p

6条回答
  •  醉酒成梦
    2020-12-30 23:41

    In your first example for every iteration the pool is drained. This makes sense if the body of the iteration involves a lot of autoreleased objects.

    The second example will only drain the pool once after the loop.

    So if the internals of the loop are causing the memory bloat then go for option one. If the memory bloat over the whole loop is acceptable then loop then use option two.

提交回复
热议问题