CFTree leaks its children

Originator:guillaume.algis
Number:rdar://18245068 Date Originated:05-Sep-2014
Status:Open Resolved:
Product:iOS SDK Product Version:7.*, 8.0b4
Classification:Performance Reproducible:Always
 
Summary:
When releasing a CFTree, the children of this CFTree are not released, even if the documentation says so:

"Releasing a tree releases its child trees, and all of their child trees (recursively)."

This results in a 64 bytes memory leak per child of the released CFTree.

Note that:
 - This does not happen when using CFTree on OS X. The bug is present in iOS only.
 - A possible workaround is to release the children CFTree manually using CFTreeRemoveAllChildren.

Steps to Reproduce:
1. Create 2 CFTree A and B with CFTreeCreate()
2. Append B as a child of A with CFTreeAppendChild(A, B) (B's retain count is 2)
3. Release B (B's retain count is now 1)
4. Release A

Expected Results:
Releasing A automatically release B; producing no memory leak.

Actual Results:
B is never released, its retain count stays at 1, resulting in a 64 bytes memory leak.

Version:
iOS 7.1, iOS8b4

Notes:
Related blog post: http://blog.spacemanlabs.com/2011/09/cftree-leaks-its-children/

Attached is an iOS project manifesting this issue; to run under Instruments.

Configuration:
iPhone Simulator, iPad mini Retina

Comments

Attached project

The test project attached to the radar is available here: https://github.com/guillaumealgis/CFTreeLeak

By guillaume.algis at Sept. 5, 2014, 4:49 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!