iOS 4 blocks and retain counts

后端 未结 2 1165
难免孤独
难免孤独 2021-01-29 21:42

I\'m just getting started with blocks and Grand Central Dispatch. I\'ve been told (and read in the Apple Documentation) that any object referenced from within a block gets retai

2条回答
  •  别那么骄傲
    2021-01-29 22:25

    I'd say it depends what you're doing with your block. If you're not storing it anywhere and use it in the definition place (like sorting an array using a block), then it gets released along with variables referenced inside it (since it's created in stack and is marked for autorelease). If you're storing it somewhere (an array, dictionary or probably pass the block to some other function) copy the block and balance it out with autorelease before passing it along.

提交回复
热议问题