# Dirty old UMG widget instances are returned by CreateWidget()

**URL:** <https://forums.unrealengine.com/t/dirty-old-umg-widget-instances-are-returned-by-createwidget/476637>\
**Category:** UI\
**Tags:** garbage-collector, memory-management, unreal-engine, bug-report, question, UMG\
**Created:** [January 1, 2021, 11:45am UTC](https://forums.unrealengine.com/t/dirty-old-umg-widget-instances-are-returned-by-createwidget/476637 "2021-01-01T11:45:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kafumanto](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kafumanto/32/1194651_2.png) [@Kafumanto](https://forums.unrealengine.com/u/Kafumanto)\
**Post date:** [January 1, 2021, 11:45am UTC](https://forums.unrealengine.com/t/dirty-old-umg-widget-instances-are-returned-by-createwidget/476637/1 "2021-01-01T11:45:15Z")

</div>

With UE4.26,a call to [CreateWidget()](https://docs.unrealengine.com/en-US/API/Runtime/UMG/Blueprint/CreateWidget/index.html) can return an old “dismissed” instance of a UMG widget if the same name is used. The returned instance retains the old state of when it was supposedly “dismissed”. This was not happening in the previous versions of UE4, where a newly fresh instance was returned.

Steps to reproduce:

1. Add a _Master_ widget on screen using CreateWidget() and explicitly setting the WidgetName parameter. Ensure this Master widget is containing some components that can retain state (e.g. a _UEditableTextBox_);
2. Remove the _Master_ widget (e.g. calling [RemoveAllWidgets()](https://docs.unrealengine.com/en-US/API/Runtime/UMG/Blueprint/UWidgetLayoutLibrary/RemoveAllWidgets/index.html))
3. (the Master widget instance should now not have any reference to it, so it should not be a _not reachable object_ and be garbage collected when possible)
4. Using a button/timer, re-create the Master widget as done in step 1 (i.e. calling CreateWidget() and explicitly setting the WidgetName parameter to the same previous value)
5. In UE4.26, the “disposed” instance is returned retaining its old state. Instead, a new fresh instance is expected (and this was what happened in UE4.25 and before).

A workaround (that demonstrates also point 3), is forcing the garbage collection calling _GEngine-\>PerformGarbageCollectionAndCleanupActors()_ between step 2 and step 4.

In the attached test project, you can verify the bug inserting some text in the editable text box widget. Pressing the first button, you can see the bug; pressing the second button you can see the workaround.

In the project, step 4 is implemented using a timer from the Game Mode, to be sure that no references to the old widget instance were retained somewhere.  
In addition, the console command “obj refs name=[widgetname] shortly” is executed before and after all the relevant command. In the output log, it confirms (between step 2 and step 4) that the “disposed” widget instance is not reachable and is waiting to be garbage collected, writing the message “_HUD\_C /Engine/Transient.UnrealEdEngine\_0:GameInstance\_0.MyHUD is not currently reachable._”

UMGRecycleBug.zip - Sample project

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0d5d0b83](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0d5d0b83](https://forums.unrealengine.com/u/anonymous_user_0d5d0b83)\
**Post date:** [January 5, 2021, 3:20pm UTC](https://forums.unrealengine.com/t/dirty-old-umg-widget-instances-are-returned-by-createwidget/476637/2 "2021-01-05T15:20:48Z")

</div>

Hello,

We’ve made a switch to a new bug reporting method using a more structured form. Please visit the link below for more details and report the issue using the new Bug Submission Form. Feel free to continue to use this thread for community discussion around the issue.

Thanks

---

<div class="post-metadata">

**Author:** ![Kafumanto](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kafumanto/32/1194651_2.png) [@Kafumanto](https://forums.unrealengine.com/u/Kafumanto)\
**Post date:** [January 5, 2021, 3:25pm UTC](https://forums.unrealengine.com/t/dirty-old-umg-widget-instances-are-returned-by-createwidget/476637/3 "2021-01-05T15:25:21Z")

</div>

Hi , thanks. I already submitted it also on UDN.
