(Tested on OS X 10.7.2)
The purpose of this example is to show that NSTreeController (in specific use cases) will hold on to data source objects that are not referenced anymore outside of the controller. The essentials of such use case are:
-
An object A is currently "selected" by the NSTreeController
-
The application code replaces object A with some object B and does not hold on to object A any longer (releasing it)
Then object A will still not be deallocated because NSTreeController seems to not to release it.
-
Run the app in Instruments with the "Allocations" instrument
-
Select the "Statistics" view; sort by category column
-
Uncheck graph for all allocations
-
Scroll window to category "JJNode"; click the checkmark to graph allocations for this category
-
Expand all nodes in the test application's window; note that a node named "I am number ..." will be replaced by some other every two seconds
-
Note in the instruments statistics view that the total number of live nodes stays the same
-
Now select the "I am number ..." node
-
You will find in instruments that as soon as the "I am number ..." node changes to a new number, the total number of live JJNodes has increased by one. This is wrong.
You can work around this problem by programmatically deselecting a node before it is being replaced in the NSTreeViewController's data source, e.g.:
[treeController setSelectionIndexPath:nil];
This bug was submitted to Apple through radar # 10782119