Hi,
I wrote a small app in Obj-C that uses garbage collection. I combined to strings like this:
But somehow, s3 ends up being (null). Why? Doesn't the stringByAppendingString: method copy the values of s1 and s2 into s3?
If I'm wrong, how else could I free the memory of s1 and s2 without losing s3?
I wrote a small app in Obj-C that uses garbage collection. I combined to strings like this:
Code:
// Initialize two strings.
NSString *s1 = [[NSString alloc] initWithString:@"apple"];
NSString *s2 = [[NSString alloc] initWithString:@"juice"];
// Combine them into a third string.
NSString *s3 = [s1 stringByAppendingString:s2];
// Make the first two strings ready to be recycled by GC.
s1 = nil;
s2 = nil;
But somehow, s3 ends up being (null). Why? Doesn't the stringByAppendingString: method copy the values of s1 and s2 into s3?
If I'm wrong, how else could I free the memory of s1 and s2 without losing s3?