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

# XApuDisconnect

> XApuDisconnect

Disconnects from the hardware server and release all resources allocated during [XApuConnect](https://docs.xbox.com/reference/audio/xapu/functions/xapuconnect.md).

## Syntax

```cpp theme={null}
HRESULT XApuDisconnect(  
         XApuHandle handle  
)  
```

### Parameters

*handle*   \_In\_\
Type: XApuHandle

Handle returned by calling [XApuConnect](https://docs.xbox.com/reference/audio/xapu/functions/xapuconnect.md).

### Return value

Type: HRESULT

Returns `S_OK` if successful; otherwise, returns an error code.

## Remarks

In addition to disconnecting from the hardware server, this call will also free [XApuConnectOutputParameters::baseData](https://docs.xbox.com/reference/audio/xapu/structs/xapuconnectoutputparameters.md) and close the [XApuConnectOutputParameters::resultReadyEvent](https://docs.xbox.com/reference/audio/xapu/structs/xapuconnectoutputparameters.md) handle.

If [XApuDisconnect](https://docs.xbox.com/reference/audio/xapu/functions/xapudisconnect.md) is called before all the enqueued commands are processed, it will release all the resources and return this error code [XAPU\_E\_PENDING\_RESULTS](https://docs.xbox.com/reference/audio/xapu/enums/xapuerrors.md).

The caller must wait for the result of the last command being enqueued before calling [XApuDisconnect](https://docs.xbox.com/reference/audio/xapu/functions/xapudisconnect.md), otherwise a catastrophic failure might happen in the hardware which will disable other active XAPU clients.

It is not recommended to call [XapuConnect](https://docs.xbox.com/reference/audio/xapu/functions/xapuconnect.md) and [XApuDisconnect](https://docs.xbox.com/reference/audio/xapu/functions/xapudisconnect.md) often to start and stop streams as those calls are time consuming and could also lead to resource losses due to memory fragmentation. Instead [XapuConnect](https://docs.xbox.com/reference/audio/xapu/functions/xapuconnect.md) should be called once upon initialization of the streaming session, then [XApuCommandType::Activate](https://docs.xbox.com/reference/audio/xapu/enums/xapucommandtype.md) and [XApuCommandType::Deactivate](https://docs.xbox.com/reference/audio/xapu/enums/xapucommandtype.md) should be used to start and stop streams during streaming. At the end of the streaming session, [XApuDisconnect](https://docs.xbox.com/reference/audio/xapu/functions/xapudisconnect.md) should be called. This is true for all XAPU clients.

## Requirements

**Header:** xapu.h

**Library:** xapu.lib

**Supported platforms:** XBOX Series X|S

## Conceptual documentation

* [XAPU overview](https://docs.xbox.com/build/console-features/audio/overviews/xapu-overview.md)

## See also

[XApuConnect](https://docs.xbox.com/reference/audio/xapu/functions/xapudisconnect.md)\
[XAPU](https://docs.xbox.com/reference/audio/xapu/xapu_members.md)


## Related topics

- [XApuConnect](https://docs.xbox.com/reference/audio/xapu/functions/xapuconnect.md)
- [XApuConnectOutputParameters](https://docs.xbox.com/reference/audio/xapu/structs/xapuconnectoutputparameters.md)
- [Single-stream Opus audio decoding with the XAPU API](https://docs.xbox.com/build/console-features/audio/overviews/xapu-overview-single-stream-audio-decode.md)
- [XAPU](https://docs.xbox.com/reference/audio/xapu/xapu_members.md)
- [XAPU overview](https://docs.xbox.com/build/console-features/audio/overviews/xapu-overview.md)
