tags:

views:

140

answers:

1

As far as I can tell, I need an UIView (or subclass of UIView) to display an CALayer on screen, right?

Then, what's the point of using CALayer for saving memory? The only point I see is when I would add several sublayers to a CALayer. Then those sublayers would not get copied 3 times for all the different tree types like presentation tree, render tree and so on. Is that right?

A: 

You can add CALayers as sublayers of another CALayer. Each individual layer does not have to be backed by a view, but the root layer in the hierarchy must be backed by a UIView.

The point is not to avoid having copies of the CALayers, which are quite lightweight, but to avoid having copies of UIViews or, more specifically, the graphics contexts that back UIViews. Those take up considerably more memory.

Alex
Actually, I don't believe that UIViews take up much more memory than a CALayer does. On the Mac, NSViews certainly are a lot heavier than CALayers, but UIViews are much more lightweight. In my performance testing, CALayers only come out slightly ahead of UIViews when rendering, and I didn't see much of a difference in memory footprint.
Brad Larson
Good to know. I had assumed UIViews suffer from the same limitations as NSViews.
Alex