Reusing a NSString variable - does it cause a memory leak?
Posted
by Chris S
on Stack Overflow
See other posts from Stack Overflow
or by Chris S
Published on 2009-05-10T13:31:48Z
Indexed on
2010/03/09
5:06 UTC
Read the original article
Hit count: 236
Coming from a .NET background I'm use to reusing string variables for storage, so is the code below likely to cause a memory leak? The code is targeting OS X on the iphone/itouch so no automatic GC.
-(NSString*) stringExample
{
NSString *result = @"example";
result = [result stringByAppendingString:@" test"]; // where does "example" go?
return result;
}
What confuses me is an NSStrings are immutable, but you can reuse an 'immutable' variable with no problem.
© Stack Overflow or respective owner