# Plugin UI deletion always on message thread?

**URL:** <https://forum.juce.com/t/plugin-ui-deletion-always-on-message-thread/36158>\
**Category:** Audio Plugins\
**Created:** [November 14, 2019, 12:53pm UTC](https://forum.juce.com/t/plugin-ui-deletion-always-on-message-thread/36158 "2019-11-14T12:53:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alatar](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@alatar](https://forum.juce.com/u/alatar)\
**Post date:** [November 14, 2019, 12:53pm UTC](https://forum.juce.com/t/plugin-ui-deletion-always-on-message-thread/36158/1 "2019-11-14T12:53:37Z")

</div>

Hi,

I am wondering: is it safe to assume, that the DAW will always destroy the plugin UI on the message thread? I mean: will the AudioProcessorEditor always be deleted from the message thread?

I am wondering, because my plugin is using async callbacks to the message thread in some places. And I am curious, if the UI could be destroyed, while I am executing an async callback. If the UI were destroyed on the message thread, then it could not be destroyed, while executing my async message thread callback. That would be good. 🙂

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [November 14, 2019, 1:25pm UTC](https://forum.juce.com/t/plugin-ui-deletion-always-on-message-thread/36158/2 "2019-11-14T13:25:09Z")

</div>

Yes, it has to. When a Component is destroyed, it starts removing child components. All methods that modify the children’s list (addChildComponent and removeChildComponent) or a Components bounds are changed require a lock on the message manager. So if a host would destroy the plugin editor on a background thread, you would get plenty asserts firing and in release it would be undefined behaviour.

But remember to capture WeakReferences/Component::SafePointer in your asynchronous lambdas, since they can still fire AFTER the destruction happened, but not in parallel.

Reference:

> <https://github.com/WeAreROLI/JUCE/blob/develop/modules/juce_gui_basics/components/juce_Component.cpp#L473>

> <https://github.com/WeAreROLI/JUCE/blob/develop/modules/juce_gui_basics/components/juce_Component.cpp#L1475>

---

<div class="post-metadata">

**Author:** ![alatar](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@alatar](https://forum.juce.com/u/alatar)\
**Post date:** [November 14, 2019, 1:39pm UTC](https://forum.juce.com/t/plugin-ui-deletion-always-on-message-thread/36158/3 "2019-11-14T13:39:24Z")

</div>

Hi Daniel,

Thanks for the fast answer. That is interesting to hear. And good news 🙂
