I see we release boxLayer in the initWithFrame function, but use it repeatedly (in the touch response functions) after that. I guess boxLayer is retained by the superlayer and still points to the same area of memory and that’s why it works, but isn’t that bad form, and shouldn’t we release it in dealloc? (Sorry for the newbie question in chapter 22, but I am still a relative babe at this…)
It’s a great question. Yes, the view’s layer retains the boxLayer. If the view gets deallocated, its layer gets deallocated, and so all of its sublayers (like the boxLayer) get deallocated.
So, we don’t need to keep an extra retain on it.