Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on deinit UIView was deallocated while key value observers were still registered with it #94

Open
NickSuglobov opened this issue Oct 20, 2017 · 0 comments

Comments

@NickSuglobov
Copy link

NickSuglobov commented Oct 20, 2017

I have a crash:

Fatal Exception: NSInternalInconsistencyException
An instance 0x151eabd0 of class UIView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x151b6c10> ( <NSKeyValueObservance 0x14384cd0: Observer: 0x151b0090, Key path: hidden, Options: <New: YES, Old: YES, Prior: NO> Context: 0x151b0180, Property: 0x8814fc0> )

In my view I have this code:

deinit {
    stackView.arrangedSubviews.forEach { view in
      stackView.removeArrangedSubview(view)
    }
  }

After investigation I found that method removeArrangedSubview does not call removeHiddenListener. Why?

You are removing listeners by code:

deinit {
        // This removes `hidden` value KVO observers using didSet()
        { self.arrangedSubviews = [] }()
    }

But arrangedSubviews are already empty. Why don't you remove listeners for all listeners in registeredKvoSubviews array?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant