<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShaders",
  "identifier" : "/documentation/MetalPerformanceShaders/MPSTemporaryImage/readCount",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Metal Performance Shaders"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSTemporaryImage(py)readCount"
  },
  "title" : "readCount"
}
-->

# readCount

The number of times a temporary image may be read by a CNN kernel before its contents become undefined.

```
var readCount: Int { get set }
```

## Discussion

Temporary images must release their underlying textures for reuse immediately after last use. In order to facilitate *prompt* and convenient memory recycling, each time a [`MPSTemporaryImage`](/documentation/MetalPerformanceShaders/MPSTemporaryImage) object is read by an `encode` method of an [`MPSCNNKernel`](/documentation/MetalPerformanceShaders/MPSCNNKernel) object, the value of its [`readCount`](/documentation/MetalPerformanceShaders/MPSTemporaryImage/readCount) property is automatically decremented. When the value of [`readCount`](/documentation/MetalPerformanceShaders/MPSTemporaryImage/readCount) reaches 0, the underlying texture is automatically made available and reusable to the framework for its own needs (and for other [`MPSTemporaryImage`](/documentation/MetalPerformanceShaders/MPSTemporaryImage) objects prior to return from the `encode` method). The contents of the underlying texture become undefined at this time.

By default, the value of [`readCount`](/documentation/MetalPerformanceShaders/MPSTemporaryImage/readCount) is initialized to 1, indicating a temporary image that may be overwritten any number of times, but read only once.

You may change the value of [`readCount`](/documentation/MetalPerformanceShaders/MPSTemporaryImage/readCount) as desired to allow [`MPSCNNKernel`](/documentation/MetalPerformanceShaders/MPSCNNKernel) objects to read the [`MPSTemporaryImage`](/documentation/MetalPerformanceShaders/MPSTemporaryImage) object additional times. However, it is an error to change the value of [`readCount`](/documentation/MetalPerformanceShaders/MPSTemporaryImage/readCount) once it reaches 0 (it is also an error to read or write to a temporary image with a [`readCount`](/documentation/MetalPerformanceShaders/MPSTemporaryImage/readCount) value of 0). You may set the value of  [`readCount`](/documentation/MetalPerformanceShaders/MPSTemporaryImage/readCount) to 0 yourself to cause the underlying texture to be returned to the framework. Writing to a temporary image does not adjust the value of [`readCount`](/documentation/MetalPerformanceShaders/MPSTemporaryImage/readCount).

The Metal API Validation layer will assert if a temporary image is deallocated with a non-zero [`readCount`](/documentation/MetalPerformanceShaders/MPSTemporaryImage/readCount) value to help identify cases when resources are not returned promptly.

---

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)