Curly Braces in Objective-c

前端 未结 3 1103
独厮守ぢ
独厮守ぢ 2021-01-29 02:47

Note: My question is based after checking this and the answers to it.

In some bigger methods, there are pieces of code that you only want to be alive f

3条回答
  •  孤街浪徒
    2021-01-29 03:26

    What curly braces do is just to define a new scope, so you can define new variables with the same name than other outer scope variables.

    The @autoreleasepool{} block is quiet similar, but also declares an autorelease pool at the beginning and drains it at the end, so it may be better from a memory footprint point of view because all the autoreleased objects declared there will be released when exiting that scope.

提交回复
热议问题