@autoreleasepool in loop or loop in @autoreleasepool?

前端 未结 6 581
遇见更好的自我
遇见更好的自我 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:55

    I would go for version 2.

    A @autoreleasepool block will release all objects that received a autorelease when the block was finished. This will take time because it will need some cpu cycles and depending on the object, the used time can be much higher then expected.

    I think custom @autoreleasepools only make sense when working with many data > 20MB or working with Data in a non-main-thread.

    So. I recommend to avoid "short" @autoreleasepool's. Because it may slow down your execution.

提交回复
热议问题