Invoke a release too many times?

I looked at another user's code and noticed that they are called an “issue” on an NSString that they don’t own (they never called alloc / keep / copy anywhere, and that was not a property).

It looked a little weird for me, and it made me wonder if there might be any weird behavior if you call release on an object that you either don't own or whose reference count is already 0? The code below compiles / works fine without warning, so I assume there are no problems, but I was just curious.

// Releasing an object I don't own
NSString *notMyString = [NSString stringWithString:@"Not mine."];
[notMyString release]; // Ignored?

// Releasing an object I own, twice
NSString *myString = [[NSString alloc] initWithString:@"Mine."];
[myString release]; // Ref count = 0
[myString release]; // Ref count = ?
+5
source share
1 answer

, . , . undefined - , , . , , - .

+15

All Articles