I think this is a very interesting question, since it shows clear and understandable control of constants, on the one hand, and some obvious exceptions that Objective-C and clang include when processing constants of the NSString class.
I believe the following applies:
Above declarations and initializations from a question does not make any difference to memory management. It just doesn't exist. Constants are simply included in the package and are not distinguished in classical terms. The value of this value from the object class indicates the place of memory of the package, where the string constant. You can easily find this by comparing the address of such an NSString and its object class. The string address is very low, indicating a range of address addresses of the bundle. You can see that the addresses of the other lines that were initialized in the code indicate very different locations. Objective-C runtime does not perform any memory management on string constants, as it would be rather inconvenient to "release" or remove something from the package. So, if you play with this in a non-ARC environment, you will see that save and release are simply ignored.
To end this by answering the question: no, there is no difference in memory management in both cases. It is simply not done. Memory is allocated by the package and the OS frees up when the application terminates. It does not apply only to declarations and assignment of an explicit constant outside the implementation, but also inside any method.
mbpro
source share