What does the following line actually do?
string = @"Some text";
Assuming that “string” is declared thusly in the header:
NSString *string;
What does the “=” actually do here? What does it do to “string”‘s reference count? In particular, assuming that for some reason “string” is not otherwise assigned to, does it need to be released?
Thanks!
The assignment is just that. The
stringpointer is basically a label that points to specific address in memory. Reassignment statement would point that label to another address in memory!It doesn’t change reference counting or do anything beyond that in Objective-C. You need to maintain the reference count yourself, if you are running in a non-garbage-collection environment:
However, string literals don’t need to be managed, as they get allocated statically and never get deallocated! So the
releaseandretainmethods are just NOOPs (i.e. no operations). You can safely omit them.