<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGLayer/init(_:size:auxiliaryInfo:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Core Graphics",
      "CoreGraphics"
    ],
    "preciseIdentifier" : "c:@F@CGLayerCreateWithContext"
  },
  "title" : "init(_:size:auxiliaryInfo:)"
}
-->

# init(_:size:auxiliaryInfo:)

Creates a layer object that is associated with a graphics context.

```
init?(_ context: CGContext, size: CGSize, auxiliaryInfo: CFDictionary?)
```

## Parameters

`context`

The graphics context you want to create the layer relative to. The layer uses this graphics context as a reference for initialization.

`size`

The size, in default user space units, of the layer relative to the graphics context.

`auxiliaryInfo`

Reserved for future use. Pass `NULL`.

## Return Value

A CGLayer object. In Objective-C, you’re responsible for releasing this object using the function [`CGLayerRelease`](/documentation/CoreGraphics/CGLayerRelease) when you no longer need the layer.

## Discussion

After you create a [`CGLayer`](/documentation/CoreGraphics/CGLayer) object, you should reuse it whenever you can to facilitate the Core Graphics caching strategy. Core Graphics caches any objects that are reused, including [`CGLayer`](/documentation/CoreGraphics/CGLayer) objects. Objects that are reused frequently remain in the cache. In contrast, objects that are used once in a while may be moved in and out of the cache according to their frequency of use. If you don’t reuse [`CGLayer`](/documentation/CoreGraphics/CGLayer) objects, Core Graphics won’t cache them. This means that you lose an opportunity to improve the performance of your application.

---

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)