---
title: withCapacity
framework: Kernel
role: symbol
role_heading: Type Method
platforms: [driverkit 19.0+, macOS 10.15+]
path: kernel/osdictionary/3180907-withcapacity
---

# withCapacity

Allocates an OSDictionary object with preallocated capacity.

## Declaration

```occ
static OSDictionaryPtr withCapacity(uint32_t capacity);
```

```occ
static OSPtr<OSDictionary> withCapacity(unsigned int capacity);
```

## Parameters

- `capacity`: Count of allocated capacity for members in dictionary.

## Return Value

Return Value NULL on failure, otherwise the allocated OSDictionary with reference count 1 to be released by the caller.

## See Also

### Creating a Dictionary

- [withDictionary](kernel/osdictionary/3180908-withdictionary.md)
- [withObjects](kernel/osdictionary/3180909-withobjects.md)
- [merge](kernel/osdictionary/3180904-merge.md)
- [free](kernel/osdictionary/3180898-free.md)
- [flushCollection](kernel/osdictionary/3180897-flushcollection.md)
