<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLSession/finishTasksAndInvalidate()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLSession(im)finishTasksAndInvalidate"
  },
  "title" : "finishTasksAndInvalidate()"
}
-->

# finishTasksAndInvalidate()

Invalidates the session, allowing any outstanding tasks to finish.

```
func finishTasksAndInvalidate()
```

## Discussion

This method returns immediately without waiting for tasks to finish. Once a session is invalidated, new tasks cannot be created in the session, but existing tasks continue until completion. After the last task finishes and the session makes the last delegate call related to those tasks, the session calls the [`urlSession(_:didBecomeInvalidWithError:)`](/documentation/Foundation/URLSessionDelegate/urlSession(_:didBecomeInvalidWithError:)) method on its delegate, then breaks references to the delegate and callback objects. After invalidation, session objects cannot be reused.

To cancel all outstanding tasks, call [`invalidateAndCancel()`](/documentation/Foundation/URLSession/invalidateAndCancel()) instead.

> Important:
> Calling this method on the session returned by the ``doc://com.apple.foundation/documentation/Foundation/URLSession/shared`` method has no effect.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)