> ## 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.

# SetDeleteOnDestroy

> When all cache session objects corresponding to a given cache are destroyed, the cache is cleared.

When all cache session objects corresponding to a given cache are destroyed, the cache is cleared.

See **Remarks** for the ways in which a disk cache can be cleared.

## Remarks

A disk cache can be cleared in one of the following ways.

* Explicitly, by calling **SetDeleteOnDestroy** on the session object, and then releasing the session.
* Explicitly, in developer mode, by calling [ID3D12Device9::ShaderCacheControl](/reference/graphics/d3d12/interfaces/id3d12device9/methods/id3d12device9_shadercachecontrol_public) with [D3D12\_SHADER\_CACHE\_KIND\_FLAG\_APPLICATION\_MANAGED](/reference/graphics/d3d12/enums/d3d12_shader_cache_kind_flags_public).
* Implicitly, by creating a session object with a version that doesn't match the version used to create it.
* Externally, by the disk cleanup utility enumerating it and clearing it. This won't happen for caches created with the [D3D12\_SHADER\_CACHE\_FLAG\_USE\_WORKING\_DIR](/reference/graphics/d3d12/enums/d3d12_shader_cache_flags_public) flag.
* Manually, by deleting the files (`*.idx`, `*.val`, and `*.lock`) stored on disk for [D3D12\_SHADER\_CACHE\_FLAG\_USE\_WORKING\_DIR](/reference/graphics/d3d12/enums/d3d12_shader_cache_flags_public) caches. Your application shouldn't attempt to do this for caches stored outside of the working directory.

## Requirements

**Header:** d3d12\_xs.h or d3d12\_x.h\
**Library:** d3d12\_xs.lib or d3d12\_x.lib\
**Supported Platforms**: XBOX Series consoles and XBOX One family

## See Also

* [D3D12 shader cache APIs](https://microsoft.github.io/DirectX-Specs/d3d/ShaderCache.html)


## Related topics

- [D3D12_SHADER_CACHE_MODE](/reference/graphics/d3d12/enums/d3d12_shader_cache_mode_public.md)
- [XblMultiplayerDeleteSearchHandleAsync](/reference/live/xsapi-c/multiplayer_c/functions/xblmultiplayerdeletesearchhandleasync.md)
- [DestroyOwnedObject](/reference/graphics/d3d12/interfaces/id3d12lifetimetracker/methods/id3d12lifetimetracker_destroyownedobject_public.md)
- [PFMultiplayerDestroyMatchmakingTicket](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmatchmaking/functions/pfmultiplayerdestroymatchmakingticket.md)
- [PartyNetwork::DestroyEndpoint](/services/playfab/multiplayer/networking/reference/classes/PartyNetwork/methods/partynetwork_destroyendpoint.md)
