I create a single mutable string object. Now I have released the object many times, even though I allocated them only once. According to basic memory management rules, this is wrong. But then it should crash, but this never happens. I was expecting some EXC_BAD_ACCESS error.
I received the error :
malloc: *** error for object 0x6d5ac60: double free
*** set a breakpoint in malloc_error_break to debug
Why the app does not crash?
NSMutableString *firstOwner = [[NSMutableString alloc] init];
[firstOwner release];
[firstOwner release];
[firstOwner release];
NSMutableString *temporaryObject = firstOwner;
[temporaryObject release];
[temporaryObject release];
Just because a crash doesn’t happen for you doesn’t mean it won’t happen for somebody else.
You’re just illustrating a case where the app can continue to limp along after making memory management errors. The crash may not be happening because aside from blatantly over-releasing, you’re not doing anything else with the object references.
But if you attempted to use or access “
firstOwner” or “temporaryObject” later, you’d absolutely crash with EXC_BAD_ACCESS then and there. Access to non-existent or over-released objects are a primary cause of these kinds of crashes.