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

# cleanup

> Stop wallet background work and close connections.

Disposes the wallet: clears claim and optimization intervals, aborts the event stream, removes listeners, and closes connections and logging resources. Call this during application shutdown or in a script's `finally` block. Do not reuse a disposed wallet.

```typescript theme={null}
async cleanup(): Promise<void>
```

```typescript theme={null}
const { wallet } = await SparkWallet.initialize({
  mnemonicOrSeed: mnemonic,
  options: { network: "MAINNET" },
});
try {
  console.log(await wallet.getSparkAddress());
} finally {
  await wallet.cleanup();
}
```

Prefer cleanup over forcing the process to exit while work may still be pending.
