aprofromindia
aprofromindia

Reputation: 1129

NSURLSession blocks memory management

If I would recreate NSURLSession, would I be copying the block parameter passed into this function: -

- dataTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler;

To further illustrate, if I am writing NSURLSession, following ARC/Blocks best practices, should I copy the completionHandler passed into the above function, as they get called asynchronously (maybe after the stack has popped?).

Upvotes: 1

Views: 103

Answers (1)

Ben Pious
Ben Pious

Reputation: 4805

NSURLSession will copy those blocks itself.

So, no, you do not need to copy them. Note that if you elected to call copy on the completion handler, unless you yourself kept a reference to the copy, ARC would simply release the copy after you had "finished" with it, which would be immediately after the copy had been passed into the dataTaskWithRequest:completionHandler: function.

Also, there is only one completion handler passed into that method.

Upvotes: 1

Related Questions