---
title: cancel()
framework: dispatch
role: symbol
role_heading: Instance Method
path: dispatch/dispatchworkitem/cancel()
---

# cancel()

Cancels the current work item asynchronously.

## Declaration

```swift
func cancel()
```

## Discussion

Discussion Cancellation causes future attempts to execute the work item to return immediately. Cancellation does not affect the execution of a work item that has already begun. 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 work item 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.

## See Also

### Canceling a Work Item

- [isCancelled](dispatch/dispatchworkitem/iscancelled.md)
