开发者

stringwithformat gives memory leak

开发者 https://www.devze.com 2023-01-06 22:41 出处:网络
I have written code as given below strPageText=开发者_StackOverflow中文版[NSString stringWithFormat:@\"%@%@\",strPageText,data];

I have written code as given below

strPageText=开发者_StackOverflow中文版[NSString stringWithFormat:@"%@%@",strPageText,data];

This is in loop. it gives me a memory leak error.


Like Vladimir said the code does not have a memory leak.

But you are using factory method stringWithFormat to create your string. So the object is autoreleased. And if you are running this in a loop, you must be getting a lot of autoreleased objects. So for better memory management your code should handle allocating and releasing the memory of your objects:

    strPageText=[[NSString alloc] initWithFormat:@"%@%@",strPageText,data];

and the release the string at the end of the loop before next iteration.

    [strPageText release];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号