iphone – How to store CALayers for reuse? – Education Career Blog

I have a bunch of identical CALayers that I want to reuse. Often, a few of them should disappear, and then get reused in another position within the same superlayer (half a second or so later).

What is the best way (performance-wise) to keep them while they have disappeared from the screen? setHidden:YES, or setOpacity:0, or removeFromSuperLayer ? Or something else I am not thinking of?

(There are about 12 identical circle shaped CALayers with contents from a UIImage, and about 30 CAShapeLayers each one holding just a line segment -though usually in different orientations-)


You should use an nsset or nsarray to maintain a queue of unused calayers. The process would be similar to what you do when using tablecells.

As each calayer is removeFromSuperLayer’d, put it into your set and pull one out from the set when you need one.


The three you mentioned seem like all reasonable things to try. You really should test each one and see which gives your application the best performance, the results might surprise you.

Leave a Comment