Using ARC, is it now OK to assign a string value like this:
self.userName = [[NSString alloc] initWithString:self.currentParsedCharacterData];
Or does that still cause a memory leak, thus requiring me to assign it like this:
NSString *tmpString = [[NSString alloc] initWithString:self.currentParsedCharacterData];
self.userName = tmpString;
The first snippet is just fine under ARC, and is the better of the two ways. Apple has an example like this in the Transitioning to ARC guide:
and says:
The
setYearOfBirth:message with anallocedNSNumbercorresponds to your snippet.The compiler understands that, in the first case,
aPersonis going out of scope and needs to be released before that happens, and, in the second case, that there is no explicit reference to theNSNumberobject and that it must be either released or put into the autorelease pool. It takes care of both these requirements on your behalf.