# Correctly handling widget creation and removal

**URL:** <https://forums.unrealengine.com/t/correctly-handling-widget-creation-and-removal/632162>\
**Category:** UI\
**Tags:** UE4-15, unreal-engine, Widget, question, UMG\
**Created:** [August 21, 2022, 2:30pm UTC](https://forums.unrealengine.com/t/correctly-handling-widget-creation-and-removal/632162 "2022-08-21T14:30:26Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [August 21, 2022, 2:46pm UTC](https://forums.unrealengine.com/t/correctly-handling-widget-creation-and-removal/632162/4 "2022-08-21T14:46:47Z")

</div>

Widgets are a massive performance leak if you are recreating them often, like when spamming the MainMenu key to create / remove the main menu. Thing is that we have to create and remove it when desired because both hidden and removed widgets still give the full performance hit including mouse events. The fix seems to be to call the garbage collector right after using RemoveParent and as the others have said garbage collection will only work when there are no property references left.

- Related

> [[Bug report] Bad widget performance : Slate : ProcessMouseMove](https://forums.unrealengine.com/t/bad-widget-performance-slate-processmousemove/506125)

---

_[View the full topic](https://forums.unrealengine.com/t/correctly-handling-widget-creation-and-removal/632162)._
