Kyle,

Thanks for the advice.

I programmatically add subviews to a view using a loop. The loop has a lot of 
logic in it. Not all subviews are the same. Some have bindings and some do not 
and not all bindings are the same. Some subviews have additional retained 
objects with their own bindings. So I would need to loop through all these 
objects in dealloc and figure out which ones have what bindings and unbind 
them. I have never used a looping construct in a dealloc method before, so that 
is why I was hesitating.

--Richard

On Apr 28, 2012, at 7:07 PM, Kyle Sluder wrote:

> On Apr 28, 2012, at 10:17 AM, Richard Somers <rsomers...@awinets.com> wrote:
> 
>> I have a number of controls with custom bindings that are programmatically 
>> added to a view hierarchy in a window. Calling –unbind: on these controls 
>> when the window is closes is a challenge.
> 
> Why? Someone has to have called -bind::: on them. Make that thing call 
> -unbind: when your window delegate (most likely your NSWindowController 
> subclass) gets -windowWillClose:.
> 
>> 
>> But it actually does not seem to matter. If –unbind: is never called and the 
>> window is closed there are no memory leaks reported in Instruments.
> 
> You're probably leaking observers and might crash at some point. You said 
> "custom bindings"; how are your bindings implemented?
> 
>> 
>> Apple has an undocumented class NSAutounbinder which apparently addresses a 
>> problem with retain cycles when binding to File's Owner from a nib file. 
>> However I am binding programmatically not inside a nib file. But perhaps 
>> NSAutounbinder is somehow working in my behalf.
> 
> Doubtful. I believe NSAutounbinder is only used by the nib loading machinery.
> 
>> 
>> Is unbinding my programmatic bindings when the window closes something that 
>> I should worry about? 
> 
> Yes.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to