title: Getting EXC_BAD_ACCESS error (code = 1) when posting a notification with Notification Center
body: <p>I have a view controller with this method:</p>
  
  <pre><code>- (void)getImages
  {
     if (self.myEntities != nil) {
        if (self.myEntities.count &gt; 0) {
           if (self.imagesDownloader == nil) {
              self.imagesDownloader = [[ImagesDownloader alloc] initWithListener];
           }
        }
  
        for (MyEntity *myEntity in self.myEntities) {
           if (![myEntity.imageUrl isEqualToString:@""] &amp;&amp; (myEntity.imageUrl != nil)) {
              [self.imagesDownloader getImageFromServiceUrl:myEntity.imageUrl];
           }
        }
     }
  }
  </code></pre>
  
  <p>And <code>ImagesDownloader</code> is an <code>NSObject</code> subclass like this:</p>
  
  <pre><code>@implementation ImagesDownloader
  
  - (id)initWithListener
  {
     self = [super init];
     if (self) {
        [self registerNotifications];
     }
     return self;
  }
  
  - (void)registerNotifications
  {
     [[NSNotificationCenter defaultCenter] removeObserver:self
                                                     name:@"getImageDidFinish"
                                                   object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self
                                              selector:@selector(getImageDidFinish:)
                                                  name:@"getImageDidFinish"
                                                object:nil];
  }
  
  - (void)getImageFromServiceUrl:(NSString *)imageUrl
  {
     GetImage *getImage = [[GetImage alloc] init];
     [getImage queryServiceWithImageUrl:imageUrl];
  }
  
  // More instance methods
  
  @end
  </code></pre>
  
  <p>In turn, <code>GetImage</code> is another <code>NSObject</code> subclass that calls a RESTful web service by using an <code>NSURLConnection</code> object, and then, in its <code>connectionDidFinishLoading:</code> delegate method, it posts the notification the <code>imagesDownloader</code> object is observing via Notification Center:</p>
  
  <pre><code>[[NSNotificationCenter defaultCenter] postNotificationName:@"getImageDidFinish"
                                                      object:nil
                                                    userInfo:serviceInfoDict];
  </code></pre>
  
  <p>This is the call where I sometimes get the EXC_BAD_ACCESS error.</p>
  
  <p>The scenario is like this: the view controller is loaded (it is pushed into a navigation stack) and <code>getImages</code> is called. Right now, its <code>self.myEntities</code> has 3 objects, so <code>self.imagesDownloader</code> is initialized and call 3 times to <code>getImageFromServiceUrl</code>. The service is called 3 times as well, and in <code>connectionDidFinishLoading:</code>, the notification is posted the 3 times with no error.</p>
  
  <p>But I then go back and forth the view controller, and it is loaded again and same calls made. But this time, I get the error the 2nd time the notification is going to be posted from <code>connectionDidFinishLoading:</code>. I don't undersatnd why, what could I be missing?</p>
  
  <p>Thanks in advance</p>