Fwd: XCode not releasing nsstring
Fwd: XCode not releasing nsstring
- Subject: Fwd: XCode not releasing nsstring
- From: James Spencer <email@hidden>
- Date: Tue, 11 Nov 2003 21:16:41 -0600
On Nov 11, 2003, at 8:46 PM, Clark Cox wrote:
On Nov 11, 2003, at 20:20, Justin Lundy wrote:
I threw this into a new project:
NSString *releaseTest;
This is undefined, you haven't initialized releaseTest to anything. It
might be nil, it might not be, it might be anything.
if (releaseTest != nil) NSLog(@"A: releaseTest NOT nil.");
if (releaseTest == nil) NSLog(@"A: releaseTest nil.");
Clark is right insofar as the test above is meaningless.
releaseTest = [[NSString alloc] initWithString:@"test string"];
Now releaseTest has been initialized and should contain a valid pointer
to a string object
if (releaseTest != nil) NSLog(@"B: releaseTest NOT nil.");
if (releaseTest == nil) NSLog(@"B: releaseTest nil.");
This test should return NOT nil because releaseTest is no longer nil
[releaseTest release];
if (releaseTest != nil) NSLog(@"C: releaseTest NOT nil.");
if (releaseTest == nil) NSLog(@"C: releaseTest nil.");
releaseTest is still not nil, it is still whatever it was initialized
to above
and guess what the log said?
A: releaseTest nil.
B: releaseTest NOT nil.
C: releaseTest NOT nil.
Call me crazy, but shouldn't the last one say "C: releaseTest nil."?
OK, you are crazy! :)
James P. Spencer
Rochester, MN
email@hidden
"Badges?? We don't need no stinkin badges!"
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.