Search code examples
iphoneobjective-cmemory-managementdealloc

Getting EXC_BAD_ACCESS on a method call


This is really weird in my perspective. I've never seen anything like it. I put all my releases in a method called releaseMethod. Then in my dealloc and didReceiveMemoryWarning, I have [self releaseMethod]; I do this to be more object orienteted and save code because I have a lot of releases. But, occasionally (2 out of 5 times, give or take), I get EXC_BAD_ACCESS on the releaseMethod call in dealloc. The code is below. I didn't know it was possible to have a method call get bad access. I understand memory management and there is no memory involved in calling a method, right? Thanks in advance.

 - (void)dealloc {
     [super dealloc];
     [self releaseMethod];
 }

Solution

  • If you send the message release to an object that has already been deallocated, this is the message you will get. Check that you aren't overreleasing something in releaseMethod. Remember, when an object is deallocated, it will release objects that it is retaining.

    You should also put [self releaseMethod] before you call [super dealloc].