Deallocating Core Data objects in a document-based app

  • I am working on a Core Data document-based app. I cannot get the
    managed objects to deallocate when I close a document. I have the
    feeling that the problem is circular references. Or it could be

    The managed objects have various one-to-one and one-to-many
    relationships to other instances of the same entity, which would
    certainly create circular  references because of the requirement to
    model both sides of the relationship. But my understanding was that
    these would automatically be cleared up by Core Data when the
    document was closed. I further understand that if objects outside the
    CD graph retain any of the managed objects I need to break these
    'cross-border' links myself. Now in my case, I do cache a number of
    the fetched managed objects in an NSArray. I may have read the
    documentation wrong, but my impression was that if I released this
    array, thereby removing the only cross-border reference, CD would
    then be able to take over and clear up and deallocate the managed
    objects as thought the NSArray had never existed. I release it in -
    windowWillClose: but the model objects are not deallocated.

    I also clear the undo stack, as mentioned elsewhere in the
    documentation and on this list. Makes no difference.

    I assume that the CD framework will fault the managed objects when it
    closes a document. But in case it doesn't, I faulted them myself.
    Again, no difference. As an alternative, I tried sending -reset to
    the managed object context. This results in messages that when
    releasing an object in an autorelease pool, the object was found to
    have been invalidated.

    Are there further steps that I need to take?

    As regards bindings, I am a little confused as to whether the old
    problem of binding to File's Owner has gone away. File's Owner is my
    NSPersistentDocument subclass. Do I need to unbind things that are
    bound to it or not? Apple's sample apps suggest not, but some posts
    on this list suggest otherwise. I have tried, and the result is
    crashes. Any clarification on where things stand on this issue would
    be appreciated. I am using XCode 2.4.1 and targeting OS X 10.4.
previous month november 2007 next month
      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    
Go to today