***

title: Close a Hosted Fields session
icon: xmark
intro: Call the destroy method to close a session.
published: true
---------------------

For clean Markdown of any page, append .md to the page URL. For a complete documentation index, see https://docs.payroc.com/full-stack-guides/take-payments/hosted-fields/extend-your-integration/llms.txt. For full documentation content, see https://docs.payroc.com/full-stack-guides/take-payments/hosted-fields/extend-your-integration/llms-full.txt.

<Warning>
  **Important:** To call the destroy method, you must be using one of the following versions of our Hosted Fields JavaScript library:

  * **Test** - 1.7.0.261457
  * **Production** - 1.7.0.261471
</Warning>

To close an idle session of Hosted Fields, call the destroy method in your JavaScript.

```js
const hostedFields = new Payroc.hostedFields(options);
hostedFields.destroy(); 
```

After calling the destroy method, you must start a new Hosted Fields session before you can take payment from the customer. For more information about how to generate a session token, go to [Authenticate your Hosted Fields session](https://docs.payroc.com/guides/take-payments/hosted-fields/authenticate-your-hosted-fields-session).

<Note>
  **Note:** You don't need to use this method for every integration, but it is considered good practice in scenarios where Hosted Fields might run on more than one session, for example, in single-page applications.
</Note>

## What does the destroy method do?

* Removes our event listener associated with the session, so that we don't receive messages from more than one session.
* Prevents further communication between the Hosted Fields JavaScript library and your Hosted Fields.
* Helps to avoid memory leaks and duplicate event handling.