I’m trying to swap two strings but I’m not sure if what I am doing is legal (coming from java I’m new to the whole retain count memory management).
Here’s my code:
NSString *temp = [[NSString alloc] init];
temp = originalLanguageCode;
originalLanguageCode = translatedLanguageCode;
translatedLanguageCode = temp;
[temp release];
Is this allowed? I’m getting some strange bugs and I’m not sure what’s causing them, hoping that this might be it. Any help is very appreciated, thanks!
After assigning a newly allocated string to
tempyou are immediately assigningoriginalLanguageCodeto it, so the allocated string is completely lost. That is a memory leak. Then you are releasingtemp, which was originallyoriginalLanguageCode. This is an over-release.Try this instead: