# Widget component widget not garbage collected

**URL:** <https://forums.unrealengine.com/t/widget-component-widget-not-garbage-collected/408225>\
**Category:** UI\
**Tags:** garbage-collector, UE4-17, unreal-engine, Widget, question\
**Created:** [October 29, 2017, 10:21am UTC](https://forums.unrealengine.com/t/widget-component-widget-not-garbage-collected/408225 "2017-10-29T10:21:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DekanTrue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DekanTrue](https://forums.unrealengine.com/u/DekanTrue)\
**Post date:** [October 29, 2017, 10:21am UTC](https://forums.unrealengine.com/t/widget-component-widget-not-garbage-collected/408225/1 "2017-10-29T10:21:00Z")

</div>

If I add a widget component and then create a widget and set the widget in the component, then the widget is not garbage collected.

Note: The bottom “add widget component” doesn’t have a widget class set.

 ![218304-widget-gc.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/9/0/490bbc4248cbbc5347b041749a16108b5dbc7101.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e729f54e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e729f54e](https://forums.unrealengine.com/u/anonymous_user_e729f54e)\
**Post date:** [October 30, 2017, 2:59pm UTC](https://forums.unrealengine.com/t/widget-component-widget-not-garbage-collected/408225/2 "2017-10-30T14:59:27Z")

</div>

Hello DekanTrue,

This is working as intended, if a widget is being referenced in a UObject it will remain in memory. I hope that this information helps.

Make it a great day

---

<div class="post-metadata">

**Author:** ![DekanTrue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DekanTrue](https://forums.unrealengine.com/u/DekanTrue)\
**Post date:** [October 31, 2017, 10:23am UTC](https://forums.unrealengine.com/t/widget-component-widget-not-garbage-collected/408225/3 "2017-10-31T10:23:58Z")

</div>

Hi Rudy,

Two things I don’t understand then:

1. How is the bottom example storing a reference to the widget, and the top example is not?
2. Upon destroying the actor, shouldn’t all references to the widget component disappear. The widget is still not garbage collected upon actor deconstruction. I have tried to remove widget from parent and remove the reference to the widget component with no result.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e729f54e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e729f54e](https://forums.unrealengine.com/u/anonymous_user_e729f54e)\
**Post date:** [October 31, 2017, 2:10pm UTC](https://forums.unrealengine.com/t/widget-component-widget-not-garbage-collected/408225/4 "2017-10-31T14:10:48Z")

</div>

Neither widget will be removed from memory. One test you can run would be to use get all widgets of class and **uncheck** “Top Level Only”. This a quick way to see how many of a certain widget are still in memory.

---

<div class="post-metadata">

**Author:** ![DekanTrue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DekanTrue](https://forums.unrealengine.com/u/DekanTrue)\
**Post date:** [October 31, 2017, 9:02pm UTC](https://forums.unrealengine.com/t/widget-component-widget-not-garbage-collected/408225/5 "2017-10-31T21:02:09Z")

</div>

I have made that test yes. That is how I noticed the issue.  
Upon actor deconconstruction, if I force garbage collection, then the widget in the top example is cleaned. The bottom one is one.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e729f54e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e729f54e](https://forums.unrealengine.com/u/anonymous_user_e729f54e)\
**Post date:** [November 13, 2017, 8:30pm UTC](https://forums.unrealengine.com/t/widget-component-widget-not-garbage-collected/408225/6 "2017-11-13T20:30:59Z")

</div>

A widget that is created using Create widget will look for the player, then the world, then the game instance. This means that unless all of them are removed (such as when the level is changed) the widget will continue to be referenced. As long as the widget is referenced, it will not be garbage collected.

---

<div class="post-metadata">

**Author:** ![TRI99ER](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TRI99ER](https://forums.unrealengine.com/u/TRI99ER)\
**Post date:** [October 20, 2019, 2:46pm UTC](https://forums.unrealengine.com/t/widget-component-widget-not-garbage-collected/408225/7 "2019-10-20T14:46:09Z")

</div>

Why would it be intended to work that way? It just uses memory.

---

<div class="post-metadata">

**Author:** ![Cordevil](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cordevil](https://forums.unrealengine.com/u/Cordevil)\
**Post date:** [June 13, 2024, 12:40pm UTC](https://forums.unrealengine.com/t/widget-component-widget-not-garbage-collected/408225/8 "2024-06-13T12:40:07Z")

</div>

I am noticing a similar issue. I noticed because once the widget is removed the key inputs are still present. So for example I create a widget with input action anykey to make it disappear. When its removed from parent the keys are still being listened to and reacted to. Mind you I am using the old input actions from UE4. In addition Stop listening for all input actions doesnt seem to fix it either.
