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

# Shutting down

> This topic explains how to safely shut down different LaunchDarkly SDKs.

> For the complete documentation index, see [llms.txt](/llms.txt). For the full documentation snapshot, see [llms-full.txt](/llms-full.txt).

## Overview

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 Launch

Darkly 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](/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)

### .NET (client-side)

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

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

### Android

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

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

    ```kotlin title="Kotlin" 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)" theme={null}
          LDClientSDK_Free(client);
    ```

    ```c title="C SDK v2.x (native)" theme={null}
          LDClientClose(client);
    ```

    ```cpp title="C SDK v2.x (C++ binding)" theme={null}
          client->close();
    ```
  </CodeGroup>
</Accordion>

### Electron

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

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

### Flutter

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

  <CodeGroup>
    ```dart title="Dart" 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" theme={null}
          client.close()
    ```

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

### Java

Script

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

  <CodeGroup>
    ```js title="JavaScript" 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" 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" 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>

## 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#" 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)" theme={null}
          LDServerSDK_Free(client);
    ```

    ```c title="C SDK v2.x (native)" theme={null}
          LDClientClose(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" 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" theme={null}
          client.Close()
    ```
  </CodeGroup>
</Accordion>

### Haskell

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

  <CodeGroup>
    ```haskell title="Haskell" 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" 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](/sdk/features/flush#nodejs-server-side).

  To shut down:

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

### Python

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

  <CodeGroup>
    ```python title="Python" 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" theme={null}
          client.close
    ```
  </CodeGroup>
</Accordion>

### Rust

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

  <CodeGroup>
    ```rust title="Rust" 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" 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" 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](/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" theme={null}
          client.close();
    ```
  </CodeGroup>
</Accordion>
