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


CGLayerRef CGLayerCreateWithContext(CGContextRef context, CGSize size, CFDictionaryRef auxiliaryInfo);



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


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


Reserved for future use. Pass NULL.

Return Value

A CGLayer object. You are responsible for releasing this object using the function CGLayerRelease when you no longer need the layer.


After you create a CGLayerRef object, you should reuse it whenever you can to facilitate the Core Graphics caching strategy. Core Graphics caches any objects that are reused, including CGLayerRef 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 CGLayerRef objects, Core Graphics won’t cache them. This means that you lose an opportunity to improve the performance of your application.