OAStackView icon indicating copy to clipboard operation
OAStackView copied to clipboard

Cleanup KVO when view is deallocating

Open krizpoon opened this issue 8 years ago • 4 comments

May cause crash when OAStackView was deallocated but still observing subview's hidden property.

krizpoon avatar Aug 17 '16 16:08 krizpoon

Is there anything I can do to help get this PR merged?

samsymons avatar Jan 31 '17 21:01 samsymons

@samsymons Hey, thanks for the interest. Do you think you can get the travis build green again :) that would be super helpful!

nsomar avatar Feb 01 '17 09:02 nsomar

@oarrabi Absolutely, I'll take a look into that — thanks! 😄

samsymons avatar Feb 01 '17 14:02 samsymons

I have not yet had time to fix up the CI issues with this PR but hope to look into that this week; sorry about that!

I also found an edge case with this fix, where views added multiple times to the stack view will not get properly deallocated after this fix in dealloc:

[self removeObserverForViews:self.subviews];

In this case, I had a label being added to the stack view multiple times, but that line above will only remove the observer for subviews. I fixed this crash in our project by updating the fix to remove the observer for all arranged subviews, not just self.subviews.

It seems that addArrangedSubview: is assuming that it is always getting a new item, so you can have a situation where the same view is added multiple times. Does it makes sense to have addArrangedSubview: check whether the newly added subview already exists in the arranged subviews array before adding it?

samsymons avatar Feb 21 '17 03:02 samsymons