Fixing Bindings-related memory leak (Bindings->Hacks)
[permalink]
If you have bindings hooked up to File's Owner in some circumstances (like with an NSWindowController-based nib file), a retain cycle is created, and so the window controller will never get released (having an extra retain for each binding to File's Owner). An easy way to work around this is to;
- Add an NSObjectController (I call it "Fake FIle's Owner") to the nib file and the window controller class.
- Point the bindings to the controller rather than file's owner
- Hook up the window controller's outlet to point to the object controller
- [fakeFileOwner setContent: self]
Then again, this all might be Wrong. jkp_ in #macdev points out that the setContent:self will retain self twice more, with no release in sight. The only wayd that would really work is if you provided a subclass of NSObjectController that released after it setContent: and also in _startObservingObject: That might be the cleanest solution - provide a custom proxy object that doesnt retain the filesOwner and bind to that....same thing, only you have to do the overrides. So this one's in limbo(e) for now. wheeee! He's come up with a hack to work around things: - (oneway void) release;
{
// special case when count is 3, we are being retained twice by the object controller...
if ( [self retainCount] == 3 )
{
[super release];
[filesOwnerProxy setContent:nil];
return;
}
[super release];
}