title: ObjC: memory usage of delegate vs block?
body: <p>I'm comparing the memory footprint of delegate vs block in Objective-C, for solving a same problem. For example, there is a worker class who does some work:</p>
  
  <pre><code>// delegate
  @protocol WorkerDelegate : NSObject
  - (void)workHasBeenDone;
  @end
  
  // block
  typedef void (^WorkerBlock)();
  
  @interface Worker : NSObject
  
  @property (nonatomic, weak) id&lt;WorkerDelegate&gt; delegate;
  
  @property (nonatomic, copy) WorkerBlock block;
  
  - (void)doTheWork;
  
  @end
  </code></pre>
  
  <p>The code is self-explanatory, in order to know when a work has been done, I can use either the delegate or block:</p>
  
  <pre><code>@implementation MyObject
  
  - (void)workHasBeenDone
  {
      [self doCleanUp];
  }
  
  - (void)entryMethod
  {
      Worker *worker = [Worker new];
      worker.delegate = self;
      // or:
      worker.block = ^{[self doCleanUp];};
      [worker doTheWork];
  }
  
  @end
  </code></pre>
  
  <p>As far as I know, in the above code, <code>self</code> as a delegate, is in memory; And the <code>block</code> is copied on heap, but I'm not sure, <strong>which has better memory footprint?</strong></p>
  
  <p>Now I need a number of workers:</p>
  
  <pre><code>Worker *workerA = ... // created and set delegate OR block for completion notification
  Worker *workerB = ... // created and set delegate OR block for completion notification
  Worker *workerC = ... // created and set delegate OR block for completion notification
  ...
  
  NSDictionary *workers = @{
      "jobA": workerA,
      "jobB": workerB,
      ...
  };
  </code></pre>
  
  <p>In this case, block seems to be cleaner, but still, does it have better, same or worse memory footprint?</p>
  
  <p>Thanks a lot!</p>