Hello everyone. I have a test program which just allocates one object and copies it. I get a leak though and I thought those with more experience might help me. This is all command line, BTW.
Here is the program, "simple.m":
I get this output:
So, my question is that it seems that there is some kind if inadvertent autorelease going on in line: 18
Why? How?
If this is a totally stupid question please forgive me.
Here is the program, "simple.m":
Code:
[COLOR="Blue"] 1 //
2 //
3 #import <Foundation/Foundation.h>
4
5 int main(int argc, char *argv[])
6 {
7 NSString *s1, *s2;
8 s1=nil;
9 s2=nil;
10
11 NSLog(@"s1 retainCount: %u\n\n", [s1 retainCount]);
12 NSLog(@"s2 retainCount: %u\n\n", [s2 retainCount]);
13 //
14 s1 = [[NSString alloc] initWithString:@"Hello There"];
15 NSLog(@"s1: %@\n\n", s1);
16 NSLog(@"s1 retainCount: %u\n\n", [s1 retainCount]);
17 //
18 s2 = [s1 stringByAppendingString:@" Computer"];
19 NSLog(@"s2: %@\n\n", s2);
20 NSLog(@"s1 retainCount: %u\n\n", [s1 retainCount]);
21 NSLog(@"s2 retainCount: %u\n\n", [s2 retainCount]);
22 [s1 release];
23 [s2 release];
24
25 return 0;
26 }[/COLOR]
I get this output:
Code:
[COLOR="Red"]gcc -framework Foundation -o simple simple.m[/COLOR]
2010-05-18 00:56:45.769 simple[49262:903] s1 retainCount: 0
2010-05-18 00:56:45.771 simple[49262:903] s2 retainCount: 0
2010-05-18 00:56:45.771 simple[49262:903] s1: Hello There
2010-05-18 00:56:45.771 simple[49262:903] s1 retainCount: 4294967295
2010-05-18 00:56:45.772 simple[49262:903] ***
__NSAutoreleaseNoPool(): Object 0x1001105d0 of class NSCFString
autoreleased with no pool in place - just leaking
2010-05-18 00:56:45.772 simple[49262:903] s2: Hello There Computer
2010-05-18 00:56:45.772 simple[49262:903] s1 retainCount: 4294967295
2010-05-18 00:56:45.773 simple[49262:903] s2 retainCount: 1
So, my question is that it seems that there is some kind if inadvertent autorelease going on in line: 18
Why? How?
If this is a totally stupid question please forgive me.