A little test application to demo a bug in NSTreeController
Objective-C
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Sample Instruments Run.trace
TreeControllerTest.xcodeproj
TreeControllerTest
README.mdown

README.mdown

NSTreeController Memory Leaks Data Source Objects

(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:

  1. An object A is currently "selected" by the NSTreeController

  2. 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.

Executing Use Case in the Test App

  1. Run the app in Instruments with the "Allocations" instrument

  2. Select the "Statistics" view; sort by category column

  3. Uncheck graph for all allocations

  4. Scroll window to category "JJNode"; click the checkmark to graph allocations for this category

  5. 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

  6. Note in the instruments statistics view that the total number of live nodes stays the same

  7. Now select the "I am number ..." node

  8. 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.

Workaround

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