title: Block code in a method does not get run
body: <p>I have the code below to load a group of images and notify me via completionHandler when they are all done loading.  However, I find that certain dispatch_group_leave won't be called at times and my guess is imageLoader is deallocated before the block gets to run.  If I put a reference of imageLoader within the loadImageWithURL:completionHandler block, then everything works as intended.</p>
  
  <p>Is my guess of the cause correct? What's the correct fix for this issue? I know ARC does block copy in most cases automatically, should I do a block copy in this case?</p>
  
  <pre><code>- (void)loadGroupImagesAsyncWithCompletion:(void(^)(NSError *))completionHandler {
  
      dispatch_group_t group = dispatch_group_create();
      int index = 0;
  
      for (Item *item in items) {
  
          char queueLabel[30] = {0};
          sprintf(queueLabel, "loader%d", index);
          dispatch_queue_t queue = dispatch_queue_create(queueLabel, NULL);
  
          dispatch_group_enter(group);
          dispatch_async(queue, ^{
  
            ImageLoader *imageLoader = [[ImageLoader alloc] init];
            [imageLoader loadImageWithURL:url completionHandler:^(UIImage *image, NSError *error) {
                if (image) {
                   item.image = image;
                }
  
                //NOTE: if item object is referenced in this block, 
                //then there is no missed dispatch_group_leave call.
                dispatch_group_leave(group);
            }];
          });
      }
  
      // Non-blocking wait
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
          // shouldn't take more than 5 secs to load all images
          dispatch_group_wait(group, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)));
          dispatch_async(dispatch_get_main_queue(), ^{
              completionHandler(nil);
          });
      });
  }
  </code></pre>