Andrew
Andrew

Reputation: 3892

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];
 }

Upvotes: 0

Views: 288

Answers (2)

Ashish Tonse
Ashish Tonse

Reputation: 145

Put your [super dealloc] at the end of the dealloc so you can first cleanup things in your class before cleaning up things in the superclass (which you might depend on).

Upvotes: 3

PengOne
PengOne

Reputation: 48398

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].

Upvotes: 2

Related Questions