Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSNotification EXC_BAD_ACCESS

Here is the error I am getting

Thread 1:EXC_BAD_ACCESS (code=2, address=0xb7ffffc)

On this line

[[NSNotificationCenter defaultCenter] postNotificationName:AsyncImageLoadDidFinish
                                                        object:target
                                                      userInfo:[[userInfo copy] autorelease]];

In the AsyncImageView.m file.

The error stops the code but if I continue in debugger it freezes Xcode and shuts it down. How can I fix this issue?

like image 369
BigT Avatar asked Jul 18 '12 14:07

BigT


1 Answers

In init you need to register, and in dealloc you need to un register!

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:AsyncImageLoadDidFinish  object:nil];

OR

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
like image 82
Guru Avatar answered Oct 20 '22 00:10

Guru