"Reloading" an NSBrowser bound to an NSTreeController

  • At various points throughout the execution of my app, I need to
    refresh the data displayed in an NSBrowser with completely new data.

    I have an NSBrowser(@millerBrowser) bound to an NSTreeController
    (@treeController), which is in turn bound to an array of NSTreeNodes
    (@remoteTree).

    This is basically how I've been doing it (tree is the new data,
    @remoteTree is the old data):
    @remoteTree and tree are both NSArrays containing NSTreeNodes.

            (@remoteTree removeAllObjects)
            (tree each:(do (branch)
                            (@remoteTree addObject:branch)))
            (set currentPath (@millerBrowser path))
            (@treeController rearrangeObjects)
            (@millerBrowser setPath:currentPath)

    I've found that the problem with this is that it creates a HUGE memory
    leak (2MB per shot).  How can I safely replace the data without
    causing a huge memory leak?  Keep in mind that this is written in Nu,
    which is garbage collected using reference counting, so all I have to
    do is make sure the data in @remoteTree is no longer referenced.

    Is there perhaps someway to remove the data through the
    NSTreeController?
  • Given your funky syntax, it seems like you're not using KVC accessors,
    so the tree controller isn't picking up KVO notifications when you
    removeAllObjects.  You can either use KVC compliant accessors and
    mutators on the object to which @remoteTree belongs (or however Nu
    works), or you can do all your manipulation through the
    NSTreeController.  Option 1 will probably entail writing the KVC
    to-many relationship accessors so that you can use
    mutableArrayValueForKey.

    HTH,
    --Kyle Sluder
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today