# \[iOS\] UIWindow is still around after destroying the UIViewComponentPeer

**URL:** <https://forum.juce.com/t/ios-uiwindow-is-still-around-after-destroying-the-uiviewcomponentpeer/44961>\
**Category:** MacOSX and iOS\
**Created:** [March 12, 2021, 11:05am UTC](https://forum.juce.com/t/ios-uiwindow-is-still-around-after-destroying-the-uiviewcomponentpeer/44961 "2021-03-12T11:05:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mttc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mttc/32/1985_2.png) [@mttc](https://forum.juce.com/u/mttc)\
**Post date:** [March 12, 2021, 11:05am UTC](https://forum.juce.com/t/ios-uiwindow-is-still-around-after-destroying-the-uiviewcomponentpeer/44961/1 "2021-03-12T11:05:01Z")

</div>

Hi, I was investigating a crash in our app happening in `JuceUIViewController::isKioskModeView()`:

```auto
    JuceUIView* juceView = (JuceUIView*) [c view];
    jassert (juceView != nil && juceView->owner != nullptr);

    return Desktop::getInstance().getKioskModeComponent() == &(juceView->owner->getComponent());

```

in which the juceView has no owner.

It seems that the problem is caused by a `UIWindow` still being around after destroying the view’s `UIViewComponentPeer`, because (since iOS 13) a `UIWindow` is not deallocated until it’s removed from its `UIWindowScene`.

So a possible fix is in `juce_ios_UIViewComponentPeer.mm:565`

```auto
    if (! isSharedWindow)
    {
        [((JuceUIWindow*) window) setOwner: nil];
        if (@available(iOS 13.0, *)) {
            window.windowScene = nil;
        }
        [window release];
    }

```

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [March 12, 2021, 5:53pm UTC](https://forum.juce.com/t/ios-uiwindow-is-still-around-after-destroying-the-uiviewcomponentpeer/44961/2 "2021-03-12T17:53:01Z")

</div>

The change looks reasonable, but I’d like to try to reproduce the crash to make sure that I understand what’s actually breaking.

Please can you provide a set of steps which cause a JUCE app to break in this way?

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [March 24, 2021, 7:04pm UTC](https://forum.juce.com/t/ios-uiwindow-is-still-around-after-destroying-the-uiviewcomponentpeer/44961/3 "2021-03-24T19:04:52Z")

</div>

I’ve just seen this appear in a JUCE app on iOS, and can confirm that this fix appears to resolve the issue.

---

<div class="post-metadata">

**Author:** ![vberthiaume](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/vberthiaume/32/6513_2.png) [@vberthiaume](https://forum.juce.com/u/vberthiaume)\
**Post date:** [March 24, 2021, 8:37pm UTC](https://forum.juce.com/t/ios-uiwindow-is-still-around-after-destroying-the-uiviewcomponentpeer/44961/4 "2021-03-24T20:37:20Z")

</div>

I just ran into this crash on our iOS app. It happened when closing the bluetooth devices pop-up. The fix above fixed the crash, but oddly enough when that window is showing, the iOS status top bar also shows, even though it’s usually hidden. It does go away when you close the bluetooth pop-up…

Will the above fix be in develop relatively soon? Thanks!

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/2/2577654fd94cdd16a17556327411d6ee8ec4c95b.jpeg)

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [March 25, 2021, 12:50pm UTC](https://forum.juce.com/t/ios-uiwindow-is-still-around-after-destroying-the-uiviewcomponentpeer/44961/5 "2021-03-25T12:50:35Z")

</div>

I’ve merged this patch now:

> <https://github.com/juce-framework/JUCE/commit/92ca22c08095be91e9b89414ec388aca616519f7>

Please let me know if this doesn’t resolve the issue you’re seeing.

---

<div class="post-metadata">

**Author:** ![vberthiaume](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/vberthiaume/32/6513_2.png) [@vberthiaume](https://forum.juce.com/u/vberthiaume)\
**Post date:** [March 25, 2021, 2:22pm UTC](https://forum.juce.com/t/ios-uiwindow-is-still-around-after-destroying-the-uiviewcomponentpeer/44961/6 "2021-03-25T14:22:34Z")

</div>

It does fix the crash 🎉 , but I still see the status bar, which is a bit odd but not really an issue. I’m also noticing these messages in the debugger every time I open the bluetooth dialog, which I don’t think I was seeing when using directly the `JUCE version 6.0.8` commit…

```auto
Unbalanced calls to begin/end appearance transitions for <JuceUIViewController: 0x10fda1ab0>.
```

---

<div class="post-metadata">

**Author:** ![kunz](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kunz](https://forum.juce.com/u/kunz)\
**Post date:** [April 7, 2021, 8:54am UTC](https://forum.juce.com/t/ios-uiwindow-is-still-around-after-destroying-the-uiviewcomponentpeer/44961/7 "2021-04-07T08:54:10Z")

</div>

I can also report that the crash with the bluetooth dialog is fixed now.
