How does NSViewController avoid bindings memory leak? [have sample app]?

One thing I've done for the same problem is to create a proxy NSObjectController inside my nib. My NSViewController-like class has a pointer to this proxy and all bindings are bound through it. When I want to cleanup the view controller, I then do selfProxy setContent:nil on the object controller and release the view controller.In this instance the NSObjectController proxy acts as the auto-unbinder in this case.

One thing I've done for the same problem is to create a proxy NSObjectController inside my nib. My NSViewController-like class has a pointer to this proxy and all bindings are bound through it. When I want to cleanup the view controller, I then do selfProxy setContent:nil on the object controller and release the view controller.In this instance the NSObjectController proxy acts as the auto-unbinder in this case.

It's more manual and you can't just release the view by itself, but it does solve the retain problem. I'd suggest you do this: -(void) releaseTopLevelObjects { // Unbind the object controller's content by setting it to nil. SelfProxy setContent:nil; NSLog( @"topLevelObjects = %@", topLevelObjects ); topLevelObjects release; topLevelObjects = nil; } In your nib, bindings would happen through a path like: selfProxy.content.

RepresentedObject.fooValue.

Thanks! I've seen many hackish attempts at fixes on the web, but this is a workaround I would actually dare to ship. Too bad there's no real way to do the auto-unbinding, though.

– uliwitness Jan 19 '10 at 15:04.

Doing a little investigation with class-dump and friends, it looks like Apple has a private class called NSAutounbinder that takes care of this dirty work for classes such as NSViewController and NSWindowController. Can't really tell how it works or how to replicate it though. So, I can't really answer your question on how to prevent the retain cycle from happening for arbitrary bindings in a loaded nib, but perhaps it's some consolation to know that Apple is cheating, and you're not missing anything obvious.

:-).

Yes, releaseTopLevelObjects releases the view (and any other unarchived objects that may be there). At least that's what it's supposed to do. – uliwitness Jan 17 '10 at 14:20.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions