I am writing an Objective-C program that utilizes the garbage collector.
I am getting *EXC_BAD_ACCESS* in some situations, the classic example of an object being "over freed". Using some of the debugging tips in this technote, namely MallocScribble and *AUTO_LOG_COLLECTIONS*, I can see that my object is being GC'd out from under me.
With that said, here is my code.
I have an NSMutableDictionary that holds the ONLY reference to an object. In a method, I am then doing:
NSObject *object = [dictionary objectForKey:key];
NSLog(@"Object is %@", object);
[dictionary removeObjectForKey:key];
If I remove the object from the dictionary before the NSLog statement, if the GC runs at the right moment, I get the *EXC_BAD_ACCESS*. Removing from the dictionary after never fails.
Why is this?