views:

49

answers:

1

I have written code as given below

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

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

A: 

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];
lukya
This won't work. strPageText is already initialized at this point.
falconcreek
this increases the memory leak. becuse its in loop