Search code examples
cocoaxcodedebuggingnsmutablestring

"__NSAutoreleaseFreedObject(): release of previously deallocated object" out of the blue


I'm not sure if this is an error or not. The code compiles fine (no warnings), but when I enter a method, a local's value (an NSMutableString) displays this content in the debugger:

__NSAutoreleaseFreedObject(): release of previously deallocated object

enter image description here I'm not getting an exception, it looks like the contents of the string (which is not even allocated at that time) is that NSAutoReleaseFreedObject warning.

What's going on?


Solution

  • If you don't initialize a normal local variable to anything, its value is undefined — it could be anything. In practice, it will interpret the bit pattern that happens to lie on the stack where the variable is allocated as a value of the variable's type. In this case, the "anything" that the variable contains happens to be the address of that string.