<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLResource/setPurgeableState(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLResource(im)setPurgeableState:"
  },
  "title" : "setPurgeableState(_:)"
}
-->

# setPurgeableState(_:)

Specifies or queries the resource’s purgeable state.

```
func setPurgeableState(_ state: MTLPurgeableState) -> MTLPurgeableState
```

## Parameters

`state`

The desired purgeable state of a resource.

## Return Value

The prior purgeable state of the resource.

## Discussion

If `state` is [`MTLPurgeableState.keepCurrent`](/documentation/Metal/MTLPurgeableState/keepCurrent), the method returns the current purgeable state without changing it.

If `state` is [`MTLPurgeableState.nonVolatile`](/documentation/Metal/MTLPurgeableState/nonVolatile), the resource is marked to inform the caller that the data should not be discarded.

If `state` is [`MTLPurgeableState.empty`](/documentation/Metal/MTLPurgeableState/empty), the resource is marked as data that can be discarded, because the caller no longer needs the contents of the resource.

If `state` is [`MTLPurgeableState.volatile`](/documentation/Metal/MTLPurgeableState/volatile), the resource is marked as data that can be discarded, even if the caller may need the resource. `MTLResource` objects can be made purgeable, even if the caller may need the resource, where the implementation can reclaim the underlying storage at any time without informing the app. Purgeable resources may enable an app to keep larger caches of idle memory that may be useful again in the future without the risk of preventing the allocation of more important memory.

When you use purgeable memory, make sure the block of memory is locked before you access it.
This locking mechanism ensures that auto-removal policies don’t discard the data while you are accessing it.
Similarly, the locking mechanism ensures that the virtual memory system has not already discarded the data.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)