3

I have an application where I need to access model data from my subviews. I've been using bindings to pass data across views; however, the bindings to self seem to be causing retain cycles (dealloc never gets called). When should I remove the bindings if not in the dealloc method? Thanks.

P.S. I know the method of binding to a proxy object controller, but I'd like to avoid using it if possible.

Here's an example of what I've been doing:

// Top-level Project view
@interface ProjectViewController : NSViewController {
    FoldersView *foldersView;
}
@property (strong) NSObjectController *projectObjectController; // holds Project instance
end

// Displays folders
@interface FoldersView : NSView {
    FolderView *folderView;
}
@property (weak) NSObjectController *projectObjectController; // binded from parent
@property (strong) NSArrayController *foldersArrayController; // binded to project.folders
@end

// Displays selected folder
@interface FolderView : NSView
@property (weak) NSArrayController *foldersArrayController;    // binded from parent
@property (strong) NSObjectController *folderObjectController; // binded to folders.selection
@end
panupan
  • 1,212
  • 13
  • 15
  • This looks fine. Is it working? – jrturton Nov 06 '11 at 07:54
  • Yes, it actually does work OK. But I think the bindings are causing a retain cycle preventing the views from getting deallocated. When are we supposed to remove bindings if not in dealloc? Thanks. – panupan Nov 06 '11 at 18:23
  • If you're having that problem I would suggest editing this question - that isn't what you were originally asking. – jrturton Nov 07 '11 at 07:52

1 Answers1

1

The bindings are the preferred way of removing C part (boilerplate code) from the MVC trinity. So your approach to handling this problem is correct.

Eimantas
  • 48,927
  • 17
  • 132
  • 168