Curly Braces in Objective-c

前端 未结 3 1102
独厮守ぢ
独厮守ぢ 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:25

    It's just plain C syntax. You use it to open a new scope as others mentioned. What this means (this is C feature) that you can use same names for stack variables again, as they are in different scope. Also, variables you declare inside that scope will not be accessible by outside scope.

    There is no relation to memory footprint, only about code organization.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-29 03:29

    Based on the above example, is this a valid way of lowering the memory footprint of an application?

    No. They're not even related. Neither are they related to @autoreleasepool - this usage of curly braces is the plain C way of opening a new scope.

    0 讨论(0)
提交回复
热议问题