开发者

stringwithformat gives memory leak

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜