<!--
{
  "documentType" : "article",
  "framework" : "ObjectiveC",
  "identifier" : "/documentation/ObjectiveC/objc_cache",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "objc_cache"
}
-->

# objc_cache

Performance optimization for method calls. Contains pointers to recently used methods.

## Discussion

To limit the need to perform linear searches of method lists for the definitions of frequently accessed methods—an operation that can considerably slow down method lookup—the Objective-C runtime functions store pointers to the definitions of the most recently called method of the class in an `objc_cache` data structure.

## Topics

### Fields

[mask](/documentation/ObjectiveC/1808499-mask)

An integer specifying the total number of allocated cache buckets (minus one). During method lookup, the Objective-C runtime uses this field to determine the index at which to begin a linear search of the `buckets` array. A pointer to a method’s selector is masked against this field using a logical AND operation (`index = (mask & selector))`. This serves as a simple hashing algorithm.

[occupied](/documentation/ObjectiveC/1808501-occupied)

An integer specifying the total number of occupied cache buckets.

[buckets](/documentation/ObjectiveC/1808503-buckets)

An array of pointers to [`Method`](/documentation/ObjectiveC/Method) data structures. This array may contain no more than `mask + 1` items. Note that pointers may be `NULL`, indicating that the cache bucket is unoccupied, and occupied buckets may not be contiguous. This array may grow over time.



---

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)