objective c - Should I need to unbind cocoa-bindings in dealloc of windowController? -
i have window controller , view controller use core data bindings, want able have views really, deallocated. want reset
managedobjectcontext , @ point have given memory possible.
i have found required unbind
things i've bound in nib, or moc keeps nib objects retained.
the issue exec_bad_access trace:
if not unbind of bindings, created in interface builder, reset
on moc causes exec_bad_access because bindings attempting reflect changes in moc in view that's gone, through array controller should gone, isn't.
so did in window controller's dealloc:
- (void) dealloc { nslog(@"wincon dealloc"); @autoreleasepool { // remove subview ensure subview dealloc [_viewcontroller.view removefromsuperviewwithoutneedingdisplay]; // tear down bindings ensure moc can reset (nsobject<nskeyvaluebindingcreation>* object in @[_watcherac, _watcherstimestreecontroller, _watchertableview, _itemsoutlineview]) { (nsstring* binding in [object exposedbindings]) [object unbind:binding]; } } }
which triggered way:
- (void) switchtobackgroundmode { nslog(@"switchtobackgroundmode"); // hide menu , dock icon [nsapp setactivationpolicy:nsapplicationactivationpolicyaccessory]; // force every view deallocate before reset @autoreleasepool { // need check loaded prevent closing closed window , // triggering second call applicationshouldterminateafterlastwindowclosed if ([self.wincon iswindowloaded]) [self.wincon close]; self.wincon = nil; } nslog(@"about resetcoredatastack"); [self resetcoredatastack]; }
... , don't errors resetcoredatastack
the stack trace above comes log file this:
2014-05-29 15:54:35.794 myapp[10230:303] switch bg in appshouldterminate 2014-05-29 15:54:35.794 myapp[10230:303] switchtobackgroundmode 2014-05-29 15:54:35.808 myapp[10230:303] wincon dealloc 2014-05-29 15:54:35.830 myapp[10230:303] resetcoredatastack 2014-05-29 15:54:35.830 myapp[10230:303] reset core data {exception thrown iff wincon dealloc doesn't unbind everything}
and window controller dealloc called when it's nilled in autoreleasepool, moc reset causes exec_bad_access unless wincon dealloc unbind
on bunch of crap in nib.
so question is:
given nib owned custom window controller (self.wincon
) arraycontroller objects bound external managedobjectcontext, needs done force in nib released , unbound? there step i'm missing causes me have unbinding manually?
[edit] new debug code:
nslog(@"wincon dealloc"); @autoreleasepool { // remove subview ensure subview dealloc [_viewcontroller.view removefromsuperviewwithoutneedingdisplay]; _viewcontroller = nil; self.window = nil; } @autoreleasepool { // tear down bindings ensure moc can reset (nsobject<nskeyvaluebindingcreation>* object in @[_watcherac, _watcherstimestreecontroller, _watchertableview, /*_itemsoutlineview*/]) { nslog(@"bindings %@", [object classname]); (nsstring* binding in [object exposedbindings]) { nslog(@"bi %@: %@", binding, [object infoforbinding:binding]); [object unbind:binding]; } }
the log below bindinginfo bindings still alive when dealloc called windowcontroller
2014-05-29 21:00:39.967 salewatch[11249:303] wincon dealloc 2014-05-29 21:00:39.975 salewatch[11249:303] bindings nsarraycontroller 2014-05-29 21:00:39.978 salewatch[11249:303] bindings nstreecontroller 2014-05-29 21:00:39.989 salewatch[11249:303] bi contentset: { nsobservedkeypath = "selection.fetchtimesforoutlineview"; nsobservedobject = "[entity: swwebstorewatcher, number of selected objects: 1]"; } 2014-05-29 21:00:39.991 salewatch[11249:303] bindings nstableview 2014-05-29 21:00:39.991 salewatch[11249:303] bi selectionindexes: { nsobservedkeypath = selectionindexes; nsobservedobject = "[entity: swwebstorewatcher, number of selected objects: 1]"; } 2014-05-29 21:00:40.001 salewatch[11249:303] bi content: { nsobservedkeypath = arrangedobjects; nsobservedobject = "[entity: swwebstorewatcher, number of selected objects: 1]"; } 2014-05-29 21:00:40.020 salewatch[11249:303] resetcoredatastack
i forced wincon.window = nil in new code, , these 3 objects still aren't nil, though outlineview treecontroller did become nil. there retain cycle here, don't see how it'd fault... yet.
Comments
Post a Comment