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

# XApuDisconnect

> XApuDisconnect

# XApuDisconnect

Disconnects from the hardware server and release all resources allocated during [XApuConnect](/reference/audio/xapu/functions/xapuconnect).

## Syntax

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

### Parameters

*handle*   \_In\_\
Type: XApuHandle

Handle returned by calling [XApuConnect](/reference/audio/xapu/functions/xapuconnect).

### 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](/reference/audio/xapu/structs/xapuconnectoutputparameters) and close the [XApuConnectOutputParameters::resultReadyEvent](/reference/audio/xapu/structs/xapuconnectoutputparameters) handle.

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

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

It is not recommended to call [XapuConnect](/reference/audio/xapu/functions/xapuconnect) and [XApuDisconnect](/reference/audio/xapu/functions/xapudisconnect) 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](/reference/audio/xapu/functions/xapuconnect) should be called once upon initialization of the streaming session, then [XApuCommandType::Activate](/reference/audio/xapu/enums/xapucommandtype) and [XApuCommandType::Deactivate](/reference/audio/xapu/enums/xapucommandtype) should be used to start and stop streams during streaming. At the end of the streaming session, [XApuDisconnect](/reference/audio/xapu/functions/xapudisconnect) 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](/build/console-features/audio/overviews/xapu-overview)

## See also

[XApuConnect](/reference/audio/xapu/functions/xapudisconnect)\
[XAPU](/reference/audio/xapu/xapu_members)


## Related topics

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