# Widget GarbageCollection Not working

**URL:** <https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889>\
**Category:** UI\
**Tags:** garbage-collector, Destroy, garbage-collection, unreal-engine, Widget, question\
**Created:** [November 29, 2017, 3:05pm UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889 "2017-11-29T15:05:07Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rumbleball](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rumbleball](https://forums.unrealengine.com/u/Rumbleball)\
**Post date:** [November 29, 2017, 3:05pm UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/1 "2017-11-29T15:05:07Z")

</div>

There are already some posts around the forum having issues with Widgets and GC and it is still an issue. It is said that Widgets get GarbageCollected. I don’t see it working.

Here is the test project. Just press play. Widgets are in /Content

Project Download: [https://drive.google.com/open?id=19P5i44B8Y3d-po7B6uAn1O\_J2cjDKxak](https://drive.google.com/open?id=19P5i44B8Y3d-po7B6uAn1O_J2cjDKxak)

If I’m doing something wrong, please explain.

---

<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 30, 2017, 4:02pm UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/2 "2017-11-30T16:02:54Z")

</div>

Hello

I have provided a link to a similar question that I believe has the information that you are looking for. Please take a look at the thread provided.

Link: [Widget component widget not garbage collected - UI - Epic Developer Community Forums](https://answers.unrealengine.com/questions/719972/widget-component-widget-not-garbage-collected.html)

Make it a great day

---

<div class="post-metadata">

**Author:** ![Rumbleball](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rumbleball](https://forums.unrealengine.com/u/Rumbleball)\
**Post date:** [November 30, 2017, 4:08pm UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/3 "2017-11-30T16:08:40Z")

</div>

Discussion with Everynone about this in another thread.

> **[How to destroy UMG widget?](https://forums.unrealengine.com/questions/156034/how-to-destroy-umg-widget.html)**
>
> Hi, How can I destroy UMG widget? If I call “Remove from Parent” it stil exists in memory…

---

<div class="post-metadata">

**Author:** ![Rumbleball](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rumbleball](https://forums.unrealengine.com/u/Rumbleball)\
**Post date:** [November 30, 2017, 5:40pm UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/4 "2017-11-30T17:40:16Z")

</div>

Thanks Rudy,

“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.”

Seriously? I would not call that garbage collection if even the world needs to die before they get picked up. If the world is dead nobody cares about the garbage any more (Well, some might).

---

<div class="post-metadata">

**Author:** ![Rumbleball](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rumbleball](https://forums.unrealengine.com/u/Rumbleball)\
**Post date:** [December 6, 2017, 2:58pm UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/5 "2017-12-06T14:58:19Z")

</div>

_poke_ not solved.

---

<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:** [December 7, 2017, 6:38pm UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/6 "2017-12-07T18:38:17Z")

</div>

I downloaded the project provided and ran a few tests. I found that this is working as intended.

---

<div class="post-metadata">

**Author:** ![Rumbleball](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rumbleball](https://forums.unrealengine.com/u/Rumbleball)\
**Post date:** [December 9, 2017, 5:45pm UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/7 "2017-12-09T17:45:24Z")

</div>

If it is working as you said:

“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.”

Yes, then it is working as intended. But GarbageCollection should collect the garbage while the game runs, not afterwards. When even the GameInstance needs to die to free up widget memory, the game is shut down. If the game is shut down, I don’t care if the GarbageCollector frees widget memory, as the process is done, dead, finished. The operating system will free the used memory anyway.

So it would be nice to have the widget garbage collection working during game time.

---

<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:** [December 11, 2017, 4:08pm UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/8 "2017-12-11T16:08:26Z")

</div>

Using the public tracker you find that this was reported previously. However, it was closed as a won’t fix. I have provided a link to the public tracker. Please feel free to use the link below for further information.

Link: [Unreal Engine Issues and Bug Tracker (UE-22560)](https://issues.unrealengine.com/issue/UE-22560)

---

<div class="post-metadata">

**Author:** ![RotemS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RotemS](https://forums.unrealengine.com/u/RotemS)\
**Post date:** [December 11, 2017, 4:21pm UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/9 "2017-12-11T16:21:35Z")

</div>

What is the reasoning for not fixing it? If it’s working “as intended” then obviously the intention is wrong.

---

<div class="post-metadata">

**Author:** ![Nameless\_Voice](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nameless_voice/32/747563_2.png) [@Nameless\_Voice](https://forums.unrealengine.com/u/Nameless_Voice)\
**Post date:** [January 15, 2018, 1:37am UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/10 "2018-01-15T01:37:41Z")

</div>

This is a serious memory leak, and there’s no way to even clean up the mess manually.  
How can that be a “won’t fix”?

Any system which dynamically creates widgets as part of its setup will leak memory each time it is activated.

The case where I saw this problem was while dynamically creating widgets for the sole purpose of rendering them to a texture. The widgets are only used inside the blueprint function which sets them up and renders them, they aren’t even drawn.  
Each time the texture is rendered, more widgets are created and never garbage collected.

The standard expectation with garbage collection is anything that isn’t referenced any more will be cleaned up, but that isn’t the case here. It’s even worse in this case, because there’s no way to manually destroy or unload a widget once it’s been created.

---

<div class="post-metadata">

**Author:** ![Rumbleball](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rumbleball](https://forums.unrealengine.com/u/Rumbleball)\
**Post date:** [January 17, 2018, 8:43pm UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/11 "2018-01-17T20:43:58Z")

</div>

thanks, realy appreaciated.

Rudy, your turn.

---

<div class="post-metadata">

**Author:** ![Rumbleball](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rumbleball](https://forums.unrealengine.com/u/Rumbleball)\
**Post date:** [January 17, 2018, 8:44pm UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/12 "2018-01-17T20:44:10Z")

</div>

Thanks, realy appreciated.

---

<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:** [January 18, 2018, 3:56pm UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/13 "2018-01-18T15:56:01Z")

</div>

After doing some digging I was able to find an issue dealing with hard references being created by the Create widget node’s output pin. This appears to have been resolved in 4.19. I have provided a link below to the public tracker. Please feel free to use the link provided for more information.

Link: [Unreal Engine Issues and Bug Tracker (UE-51408)](https://issues.unrealengine.com/issue/UE-51408)

Make it a great day

---

<div class="post-metadata">

**Author:** ![Nameless\_Voice](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nameless_voice/32/747563_2.png) [@Nameless\_Voice](https://forums.unrealengine.com/u/Nameless_Voice)\
**Post date:** [January 19, 2018, 1:50am UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/14 "2018-01-19T01:50:37Z")

</div>

I can confirm. This is fixed in the 4.19.0-preview 1.

The excess widgets will accumulate, but will then be correctly cleaned up when the garbage collector activates. (I triggered the GC manually in my testing.)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [January 19, 2018, 8:02am UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/15 "2018-01-19T08:02:28Z")

</div>

This is great news. @Rumbleball Perseverance paying off and all.

---

<div class="post-metadata">

**Author:** ![RiverBB123](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RiverBB123](https://forums.unrealengine.com/u/RiverBB123)\
**Post date:** [June 23, 2018, 7:18am UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/16 "2018-06-23T07:18:04Z")

</div>

hi,Nameless Voice  
the GC is delayed in UE4?  
I use Rumbleball’s test project on 4.19.2，but the BP\_TextWidget still exist on memory  
here is image:

 ![245143-createwidget.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/2/4/124f508e260c11d7e403a8f04766832e8a76532d.jpeg)

can u show me you test project

---

<div class="post-metadata">

**Author:** ![Nameless\_Voice](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nameless_voice/32/747563_2.png) [@Nameless\_Voice](https://forums.unrealengine.com/u/Nameless_Voice)\
**Post date:** [June 25, 2018, 12:15am UTC](https://forums.unrealengine.com/t/widget-garbagecollection-not-working/410889/17 "2018-06-25T00:15:05Z")

</div>

I don’t have a test project handy any more. Did you try manually running the garbage collector in your Blueprint to see if the memory is cleared up?
