ios-360-videos icon indicating copy to clipboard operation
ios-360-videos copied to clipboard

SpriteKit/SceneKit Retain Cycles

Open jaredsinclair opened this issue 8 years ago • 0 comments

The following should be submitted to Apple as a bug radar.

Bug

Setting an SKScene as the contents of an SCNMaterialProperty leads to numerous retain cycles in internal SceneKit and SpriteKit classes.

Steps to Reproduce

  1. Set up an SKScene with a single SKVideoNode child.
  2. Set up an SCNNode using a primitive geometry.
  3. Assign the SKScene as the contents of the SCNNode’s geometry.firstMaterial.diffuse.contents.
  4. Relinquish all references to the SKScene and SCNNode.

Expected Behavior

The SKScene and the SCNNode should be deallocated.

Actual Result

The SKScene and many other instances are leaked due to numerous retain cycles.

Notes

Please run the attached sample code on iOS 10. You can see the retain cycles plainly illustrated using Xcode 8's visual memory debugger. The Leaks instrument will also show some of these leaks when running on a real device running iOS 10. I have not been able to get Instruments to report a leak on iOS 9, and intermittently on iOS 10. However, the visual memory debugger in Xcode 8 always reveals the retain cycles.

You can verify that SCNMaterialProperty.contents is the culprit by commenting out Line 63 in PlayerScene.m.

Uploads

Sample Project: https://www.dropbox.com/s/1j0ib2ojbr1xbym/Memory%20Leak.zip?dl=0

Screenshot

sk-retain-cycle

jaredsinclair avatar Sep 16 '16 14:09 jaredsinclair