I am getting NSCFString for the code below:
NSString *urlString;
/* leak showing below line */
urlString = [urlString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
How do you solve this leak?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Most likely you created your urlString using
+alloc/initWith.... If that’s the case then you own theurlStringreference and are responsible for releasing it at some point. However, when you get to the line you pasted in the question, you’re overwriting theurlStringreference with a new string reference, sincestringByReplacingOccurrencesOfString:withString:returns a new string object (ie, it doesn’t modify the string in place).My recommendation would be to use an
NSMutableStringinstead, which does allow in-place string manipulation.