UIDynamicAnimator references its UICollectionViewLayout in -dealloc

Originator:gmws82
Number:rdar://15062440 Date Originated:09/23/13
Status:Open Resolved:No
Product:iOS SDK Product Version:7.0
Classification:Crash Reproducible:Always
 
Summary:
A UIDynamicAnimator initialized using -initWithCollectionViewLayout: does not hold a strong reference to its collection view layout but attempts to message it when deallocated, causing a bad access crash if the collection view layout is deallocated before the dynamic animator.

Steps to Reproduce:
1. Allocate and initialize a UICollectionViewLayout.
2. Allocate and initialize a UIDynamicAnimator using -initWithCollectionViewLayout: and passing in the collection view layout from step 1.
3. Deallocate the collection view.
4. Deallocate the dynamic animator.

Expected Results:
Nothing; two objects are allocated and then deallocated with no effect on the behavior of the app at runtime.

Actual Results:
The app crashes in the dynamic animator's -dealloc method because it attempts to message the non-existant collection view layout.

Version:
iOS 7.0 (11A465)

Notes:
It is not clear what type of reference the dynamic animator currently keeps to its collection view layout, but it appears neither to be a strong reference nor a weak zeroing reference because in neither case would this crash occur. Thus, one possible solution to this problem would be to expose the animator's collection view layout as a weak, readonly property, as is done with its reference view. Another possible solution would be to expose the collection view layout as a strong, readwrite property, eliminating the need to create a new animator every time the collection view's layout is replaced.

Configuration:
This occurs on my iPhone 4S running iOS 7.0 (11A465) when using Xcode 5 on a Macbook Pro with Retina Display running OS X 10.8.5. (This also occurs on the iPhone simulator that comes with Xcode 5.)

Comments


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!