Hi all,
I am up to memory management in Kochan. In playing around with strings and retain counts, I tried to invoke a seg fault.
The example from Wikipedia does it in c, thus:
But then I tried this in Obj-C, which I **think** is close to the C example, but obviously not?? , because it works, which is not what I had expected.
Any insight?
Uncommenting the expression "[myStr release];" does, I **think** do so, however.
Thanks.
I am up to memory management in Kochan. In playing around with strings and retain counts, I tried to invoke a seg fault.
The example from Wikipedia does it in c, thus:
Code:
int main (int argc, const char * argv[]) {
char *s = "Sigsegv error constant string";
*s = 'H';
But then I tried this in Obj-C, which I **think** is close to the C example, but obviously not?? , because it works, which is not what I had expected.
Code:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *myStr = @"Constant String";
myStr = [myStr stringByReplacingCharactersInRange: NSMakeRange(1, 11) withString: @"this a test"];
/*[myStr release]; */
NSLog(@"This should not work...but it does!!! %@", myStr);
[pool drain];
return 0;
}
Any insight?
Uncommenting the expression "[myStr release];" does, I **think** do so, however.
Thanks.