> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Session.close()

> Session.close() → [None](https://docs.python.org/3/builtins/constants.html#None)

Close this session and free all associated resources.

The session cannot be used after calling this method.

Closing a session frees its port so it can be reused by another session or another process.

This method is called by the `__del__()` method so garbage collected sessions will automatically be closed.
Python synchronously garbage collects objects as soon as their last (hard) reference is lost.
In a notebook, it is thus possible to run the following cell multiple times without encountering a “port already in use” error:

```python theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
# (Re)assigning the `session` variable to garbage collect previous reference (if any).
session = None
# If a previous `session` was using port 1337, it is now free to use again (unless another process just took it).
session = tt.Session.start(tt.SessionConfig(port=1337))
```

> [!NOTE]
>
> In a notebook, evaluating/printing an object creates long lasting references to it preventing the object from being garbage collected.
> The pattern shown above will thus only work if the session object was not used as the last expression of a cell.
