NSArrayController delete objects once removed

  • Greetings,
    The logic of my application is that there is an NSArrayController
    which contains an array of object that are displayed in an
    NSTableView. The problem is that when I call removeObject it will
    remove the object, though not delete/dealloc the object and thus parts
    of the custom NSCell and NSView remain.

    Any help in addressing this would be nice.

    Thanks,
    Matthew Delves
  • > there is an NSArrayController which contains an array of object ...
    > when I call removeObject it will remove the object, though not
    > delete/dealloc

    You're probably retaining the object someplace else either explicitly
    or unintentionally. How are you creating the objects? How are you
    adding them to array controller? What is the object's -retainCount
    before you add it to the array controller? After? After it's removed?

    Cheers,
    -Joshua Emmons
  • On Dec 15, 2007, at 4:31 AM, Matthew Delves wrote:

    > The logic of my application is that there is an NSArrayController
    > which contains an array of object that are displayed in an
    > NSTableView.

    Better would be to have the array of model-layer objects actually
    owned by some other object in your system, and only *controlled* by an
    NSArrayController.

    Then when your view-layer code asks the NSArrayController to remove an
    object, it will pass that removal along to its content array, which is
    the model-layer removal.

    In general, I almost never have an NSController subclass which
    actually "owns" or "contains" the object or objects it controls.
    Doing so is fine for putting together demos in Interface Builder but
    it isn't really the kind of model-view-controller architecture needed
    for real applications.

      -- Chris
  • On 16/12/2007, at 12:28 PM, Chris Hanson wrote:

    > On Dec 15, 2007, at 4:31 AM, Matthew Delves wrote:
    >
    >> The logic of my application is that there is an NSArrayController
    >> which contains an array of object that are displayed in an
    >> NSTableView.
    >
    > Better would be to have the array of model-layer objects actually
    > owned by some other object in your system, and only *controlled* by
    > an NSArrayController.
    >

    I've separated them out, though the problem still remains. I have also
    checked the 'Deletes objects on remove' inside of IB, though the
    dealloc method isn't being called for the objects stored within the
    array.

    Any suggestions?

    Thanks,
    Matthew Delves
  • > I've separated them out, though the problem still remains. I have
    > also checked the 'Deletes objects on remove' inside of IB, though
    > the dealloc method isn't being called for the objects stored within
    > the array.

    Is your project using garbage collection? -dealloc never gets called
    on garbage collected objects, as I recall.

    Cheers,
    -Joshua Emmons
previous month december 2007 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