I assign here on a an Object a derivative of the same object. Is there any problem with this?
NSString *urlString =[TBXML textForElement:tempElement];
urlString = [urlString stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
urlString = [urlString stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
Yes, that’s fine. After running this code, there will be three
NSStringobjects in memory:[TBXML textForElement:tempElement][urlString stringByReplacingOccurrencesOfString:@" " withString:@"%20"][urlString stringByReplacingOccurrencesOfString:@"&" withString:@"&"]Each of them will have a retain count of 1 but will be autoreleased. Since you don’t keep references to 1. or 2., there’s no way you’ll be able to increase their retain counts afterwards, so at the end of the current iteration of the run loop they will be autoreleased, their retain counts will go to 0, and they will be deallocated.
The third one is in the same boat, but you do have a reference to it, so if you do something to increase its retain count (e.g., assign it to a
strong@property or add it to anNSArrray) then it may continue to exist after this iteration of the run loop. Or, if you’re just using it as a parameter to some function (maybe you just use it inNSString stringWithFormat:later on, it will get deallocated along with the other two.