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

# Shutting down

<View title="Developer" />

<View title="Federal docs" />

<View title="EU docs" />

This topic explains how to safely shut down different LaunchDarkly SDKs. This feature is available for client-side, server-side, and edge SDKs.

## Shut down the LaunchDarkly client

LaunchDarkly SDKs provide language-specific methods to shut down their instances safely.

In most applications, you do not have to manually shut down an SDK. LaunchDarkly SDKs automatically flush pending analytics events to LaunchDarkly at regular intervals.

However, when your application is about to terminate, you should shut down the LaunchDarkly client. For most SDKs, this ensures that the client releases any resources it is using, and that it delivers any pending analytics to LaunchDarkly. If your application terminates without this shutdown step, flag evaluations and contexts or users may not appear on the **Contexts** list, because they are derived from analytics events. To learn more, read [Analytics events](/docs/sdk/concepts/events).

Do not attempt to evaluate flags or otherwise use the LaunchDarkly client after it has shut down, as doing so may result in undefined behavior. Shut down the client at a point in your application's lifecycle where the client is no longer needed.

Details about each SDK's configuration are available in the SDK-specific sections below.

* [Client-side SDKs](#client-side-sdks)
* [Server-side SDKs](#server-side-sdks)
* [Edge SDKs](#edge-sdks)

## Client-side SDKs

This feature is available in the following client-side SDKs:

* [.NET (client-side)](#net-client-side)
* [Android](#android)
* [C++ (client-side)](#c-client-side)
* [Electron](#electron)
* [Flutter](#flutter)
* [iOS](#ios)
* [JavaScript](#javascript)
* [Node.js (client-side)](#nodejs-client-side)
* [React Native](#react-native)
* [Vue](#vue)

### .NET (client-side)

<Accordion title="Expand .NET (client-side) code sample">
  To shut down:

  <CodeGroup>
    ```csharp title="C#" lines wrap theme={null}
    client.Dispose();
    ```
  </CodeGroup>
</Accordion>

### Android

<Accordion title="Expand Android code sample">
  To shut down:

  <CodeGroup>
    ```java title="Java" lines wrap theme={null}
    client.close();
    ```

    ```kotlin title="Kotlin" lines wrap theme={null}
    client.close()
    ```
  </CodeGroup>
</Accordion>

### C++ (client-side)

<Accordion title="Expand C++ (client-side) code sample">
  In the C++ SDK v3.0, the client will be automatically closed.

  If you are using the C binding, you must specifically close the client. The operation blocks until all resources are free.

  To shut down:

  <CodeGroup>
    ```c title="C++ SDK v3.0 (C binding)" lines wrap theme={null}
    LDClientSDK_Free(client);
    ```
  </CodeGroup>
</Accordion>

### Electron

<Accordion title="Expand Electron code sample">
  To shut down:

  <CodeGroup>
    ```js title="JavaScript" lines wrap theme={null}
    await client.close();
    ```
  </CodeGroup>
</Accordion>

### Flutter

<Accordion title="Expand Flutter code sample">
  To shut down:

  <CodeGroup>
    ```dart title="Dart" lines wrap theme={null}
    await client.close();
    ```
  </CodeGroup>

  To learn more, read [`close`](https://pub.dev/documentation/launchdarkly_flutter_client_sdk/latest/launchdarkly_flutter_client_sdk/LDClient/close.html).
</Accordion>

### iOS

<Accordion title="Expand iOS code sample">
  To shut down:

  <CodeGroup>
    ```swift title="Swift" lines wrap theme={null}
    client.close()
    ```

    ```objectivec title="Objective-C" lines wrap theme={null}
    [client close];
    ```
  </CodeGroup>
</Accordion>

### JavaScript

<Accordion title="Expand JavaScript code sample">
  To shut down:

  <CodeGroup>
    ```js title="JavaScript" lines wrap theme={null}
    await client.close();
    ```
  </CodeGroup>
</Accordion>

### Node.js (client-side)

<Accordion title="Expand Node.js (client-side) code sample">
  To shut down:

  <CodeGroup>
    ```js title="JavaScript" lines wrap theme={null}
    await client.close();
    ```
  </CodeGroup>
</Accordion>

### React Native

<Accordion title="Expand React Native code sample">
  Calling `close` flushes all queued events and shuts all open network connections.

  To shut down:

  <CodeGroup>
    ```js title="React Native SDK, v10" lines wrap theme={null}
    await client.close();
    ```
  </CodeGroup>

  To learn more, read [`close`](https://launchdarkly.github.io/js-core/packages/sdk/react-native/docs/classes/LDClientImpl.html#close).
</Accordion>

### Vue

<Accordion title="Expand Vue code sample">
  `LDVueClient` inherits the `close()` method from the base `LDClient`. To shut down the client, retrieve it with `useLDClient()` and call `close()`.

  To shut down:

  <CodeGroup>
    ```html title="Vue SDK v3.0" lines wrap theme={null}
    <script setup>
    import { useLDClient } from '@launchdarkly/vue-client-sdk'

    const ldClient = useLDClient()

    async function shutDown() {
      await ldClient.close()
    }
    </script>
    ```
  </CodeGroup>
</Accordion>

## Server-side SDKs

This feature is available in the following server-side SDKs:

* [.NET (server-side)](#net-server-side)
* [C++ (server-side)](#c-server-side)
* [Erlang](#erlang)
* [Go](#go)
* [Haskell](#haskell)
* [Java](#java)
* [Node.js (server-side)](#nodejs-server-side)
* [Python](#python)
* [Ruby](#ruby)
* [Rust](#rust)

### .NET (server-side)

<Accordion title="Expand .NET (server-side) code sample">
  [`Dispose`](https://launchdarkly.github.io/dotnet-core/pkgs/sdk/server/api/LaunchDarkly.Sdk.Server.LdClient.html#LaunchDarkly_Sdk_Server_LdClient_Dispose_) safely shuts down the client instance.

  To shut down:

  <CodeGroup>
    ```csharp title="C#" lines wrap theme={null}
    client.Dispose();
    ```
  </CodeGroup>
</Accordion>

### C++ (server-side)

<Accordion title="Expand C++ (server-side) code sample">
  In the C++ SDK v3.0, the SDK will be automatically closed.

  If you are using the C binding, you must specifically close the client. The operation blocks until all resources are free.

  To shut down:

  <CodeGroup>
    ```c title="C++ SDK v3.0 (C binding)" lines wrap theme={null}
    LDServerSDK_Free(client);
    ```
  </CodeGroup>
</Accordion>

### Erlang

<Accordion title="Expand Erlang code sample">
  `stop_instance()`, `stop_instance(Tag)`, and `stop_all_instances()` all safely shut down client instances and release the resources associated with them.

  To shut down:

  <CodeGroup>
    ```erlang title="Erlang" lines wrap theme={null}
    ldclient:stop_all_instances()

    % Stops the default instance
    ldclient:stop_instance()

    % Stops a named instance
    ldclient:stop_instance(my_instance)
    ```
  </CodeGroup>
</Accordion>

### Go

<Accordion title="Expand Go code sample">
  When your application is about to terminate, shut down the `LDClient` with [`Close()`](https://pkg.go.dev/gopkg.in/launchdarkly/go-server-sdk.v5#LDClient.Close).

  To shut down:

  <CodeGroup>
    ```go title="Go" lines wrap theme={null}
    client.Close()
    ```
  </CodeGroup>
</Accordion>

### Haskell

<Accordion title="Expand Haskell code sample">
  To shut down:

  <CodeGroup>
    ```haskell title="Haskell" lines wrap theme={null}
    close client
    ```
  </CodeGroup>
</Accordion>

### Java

<Accordion title="Expand Java code sample">
  [`Close`](https://launchdarkly.github.io/java-core/lib/sdk/server/com/launchdarkly/sdk/server/LDClient.html#close--) safely shuts down the client instance and releases all resources associated with the client.

  To shut down:

  <CodeGroup>
    ```java title="Java" lines wrap theme={null}
    client.close();
    ```
  </CodeGroup>
</Accordion>

### Node.js (server-side)

<Accordion title="Expand Node.js (server-side) code sample">
  Unlike other LaunchDarkly SDKs, the Node.js (server-side) SDK does not automatically send pending analytics events to LaunchDarkly when it shuts down. To send analytics events, you first need to call [flush](/docs/sdk/features/flush#nodejs-server-side).

  To shut down:

  <CodeGroup>
    ```js title="JavaScript" lines wrap theme={null}
    client.close();
    ```
  </CodeGroup>
</Accordion>

### Python

<Accordion title="Expand Python code sample">
  To shut down:

  <CodeGroup>
    ```python title="Python" lines wrap theme={null}
    ldclient.get().close()
    ```
  </CodeGroup>
</Accordion>

### Ruby

<Accordion title="Expand Ruby code sample">
  Shutting down frees the resources the worker threads were using and provides an explicit signal for the Ruby SDK to send the remaining event data back to LaunchDarkly.

  To shut down:

  <CodeGroup>
    ```ruby title="Ruby" lines wrap theme={null}
    client.close
    ```
  </CodeGroup>
</Accordion>

### Rust

<Accordion title="Expand Rust code sample">
  To shut down:

  <CodeGroup>
    ```rust title="Rust" lines wrap theme={null}
    client.close();
    ```
  </CodeGroup>
</Accordion>

## Edge SDKs

This feature is available in the following edge SDKs:

* [Cloudflare](#cloudflare)
* [Fastly](#fastly)
* [Vercel](#vercel)

### Cloudflare

<Accordion title="Expand Cloudflare code sample">
  [`close`](https://launchdarkly.github.io/js-core/packages/sdk/cloudflare/docs/classes/LDClient.html#close) safely shuts down the client instance:

  <CodeGroup>
    ```ts title="TypeScript" lines wrap theme={null}
    client.close();
    ```
  </CodeGroup>
</Accordion>

### Fastly

<Accordion title="Expand Fastly code sample">
  [`close`](https://launchdarkly.github.io/js-core/packages/sdk/fastly/docs/classes/LDClient.html#close) safely shuts down the client instance:

  <CodeGroup>
    ```ts title="TypeScript" lines wrap theme={null}
    client.close();
    ```
  </CodeGroup>

  Typically, you do not need to call this method, because the client will close safely when the worker exists. However, you must [flush](/docs/sdk/features/flush#fastly) events before your worker exits to ensure that they are sent back to LaunchDarkly.
</Accordion>

### Vercel

<Accordion title="Expand Vercel code sample">
  [`close`](https://launchdarkly.github.io/js-core/packages/sdk/vercel/docs/classes/LDClient.html#close) safely shuts down the client instance:

  <CodeGroup>
    ```ts title="TypeScript" lines wrap theme={null}
    client.close();
    ```
  </CodeGroup>
</Accordion>
