objective c - Calling 'release' too many times? -


I was looking at someone else's code and saw that he did not take himself on an NSString called 'Release' ( Which had never been said

It seemed a bit awkward for me and I wonder if there can be any strange behavior if you 'release' on any object, you can either ' Themselves' or whose ref count is already 0? The code below is run properly without warning So I think there is no problem with it, but I'm just curious.

  // I release a object I have not done NSString * notMyString = [NSString stringWithString: @ "mine . "]; [No Myststring release]; // Defy? // I have an object released, NSSSing twice; * Mystrying = [[Nssting Elock] introvers string: @" My. "]; [Myself release]; // referee calculation = 0 [MyString release]; // referee calculation =?  

Yes, do not do that, your assessment is correct, as you have your understanding of ownership rules. Sending a message to an already released object is undefined behavior - sometimes you will be lucky due to other goods and nothing will happen. Sometimes you will crash immediately, sometimes later because you have corrupted some more.


Comments