I am comparing the memory size of the vs block delegate in Objective-C to solve the same problem. For example, there is a working class that does some work:
// delegate @protocol WorkerDelegate : NSObject - (void)workHasBeenDone; @end // block typedef void (^WorkerBlock)(); @interface Worker : NSObject @property (nonatomic, weak) id<WorkerDelegate> delegate; @property (nonatomic, copy) WorkerBlock block; - (void)doTheWork; @end
The code requires no explanation, in order to know when the work was done, I can use a delegate or a block:
@implementation MyObject - (void)workHasBeenDone { [self doCleanUp]; } - (void)entryMethod { Worker *worker = [Worker new]; worker.delegate = self;
As far as I know, in the above code, self as a delegate is in memory; And block copied to a bunch, but I'm not sure which one has more memory.
Now I need the number of employees:
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, ... };
In this case, the block seems to be cleaner, but, nevertheless, does it have the best, the same or the worst amount of memory?
Thanks a lot!
source share