I'm implementing didReceiveMemoryWarning in a subclass of UIViewController. My code looks something like the following:
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
[self cleanUp];
}
When my app actually received a memory warning, the app crashed with an EXC_BAD_ACCESS on the [self cleanUp]
line (a method that does exist). How could this happen? As I understand it, the framework called the didReceiveMemoryWarning
method, then released my class before it attempted to execute [self cleanUp]
. Why would this happen? How can I prevent this?
The crash was actually happening inside the
-(void)cleanUp
method, though Xcode was pointing to the line that called[self cleanUp]
. Inside the-(void)cleanUp
the code was accessing elements in an array that were already released, hence the EXC_BAD_ACCESS. Thanks to all for the helpful suggestions.