Removing view's layer from super layer leads to EXC_BAD_ACCESS

Originator:pburleson
Number:rdar://11588768 Date Originated:04-Jun-2012 01:34 PM
Status:Open Resolved:
Product:iPad SDK Product Version:5.1.1 (9B206)
Classification:Serious Bug Reproducible:Always
 
Summary:

Removing a CALayer of a view from its super layer causes any access of the view to throw a EXC_BAD_ACCESS. 

Steps to Reproduce:

1. Add a view as a subview of another view

2. Loop over the super view's layer's sublayers and call -removeFromSuperLayer

3. Try to access any property of the subview or call a method on the subview

Expected Results:

Everything continues to work

Actual Results:

EXC_BAD_ACCESS is thrown on any access of the view as it's CALayer is now invalid

Notes: 

UIView's documentation states that it's layer property is retained. Removing just the layer from its super layer should not release the layer to the point of it being deallocated since UIView should still have a retained reference to it.

The content being removed from the super view is expected as the CALayer is where it's actually being drawn, but the memory being deallocated was unexpected.

A sample project is attached. Run the app in the simulator (or a device). Tap "Add View" and then tap "Access View", which will work fine. Then tap "Remove Layers" and then tap "Access View". Crashtastic.

Comments

Sample Project

You can download the sample project here: http://cl.ly/0f0X3O1r1c122C1d2x3k

By pburleson at June 4, 2012, 6:37 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!