Widget GarbageCollection Not working

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

If I’m doing something wrong, please explain.

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

Make it a great day

Discussion with Everynone about this in another thread.

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).

poke not solved.

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

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.

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)

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

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.

thanks, realy appreaciated.

Rudy, your turn.

Thanks, realy appreciated.

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)

Make it a great day

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.)

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

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:

can u show me you test project

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?