Cancels the specified dispatch block asynchronously.
SDKs
- iOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Dispatch
Declaration
void dispatch_block_cancel(dispatch _block _t block);
Parameters
block
The dispatch block to cancel.
The result of passing
NULL
or a block object not returned by thedispatch
or_block _create dispatch
function is undefined._block _create _with _qos _class
Discussion
Cancellation causes any future execution of the dispatch block to return immediately, but does not affect any execution of the block object that is already in progress.
Release of any resources associated with the block object is delayed until execution of the block object is next attempted (or any execution already in progress completes).
Note
Take care to ensure that a block object that may be canceled does not capture any resources that require execution of the block body in order to be released, such as memory allocated with malloc(3)
on which the block body calls free(3)
. Such resources are leaked if the block body is never executed due to cancellation.