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?
Best Answer
You can add
CALayer
s as sublayers of anotherCALayer
. Each individual layer does not have to be backed by a view, but the root layer in the hierarchy must be backed by aUIView
.The point is not to avoid having copies of the
CALayer
s, which are quite lightweight, but to avoid having copies ofUIViews
or, more specifically, the graphics contexts that backUIView
s. Those take up considerably more memory.