Question about garbage collect and widgets

Hi,

I have a specific setup where an overview widget with 3 tabs dynamically creates widgets and adds them as a child to a vertical box inside the overview. Each tab contains a list of exercises (each exercise is generated as a widget with custom content and markup). Whenever I switch a tab, I clean up the vertical box and create a new list of exercises. However, constantly switching between these 3 tabs, causes many (old) widget instances to stay behind. I tried the “remove from parent” node but it doesn’t remove them from memory. There is also no proper way in UE4 to destroy a widget reference as you can do with an actor. I could reuse the created widgets again but they are dynamically generated and can have their status changed every time so then I would use bindings/ticks to update their content which is not good for performance.

I found a easy solution to remove all these unused instances that were created using a node called “garbage collect” whenever I want to clean up all old widgets and recreate only the widgets from an active tab still in memory. However, are there any risks involved using this node? I understand the principe of garbage collection but have no experience actively using it in UE4. Not sure if things may break elsewhere, when this node is called.

However, are there any risks involved
using this node? I understand the
principe of garbage collection but
have no experience actively using it
in UE4. Not sure if things may break
elsewhere, when this node is called.

I’ve been using it for years. Never run into anything unforeseen. For a widget to be garbage collected, it must have no parent container and be completely unreferenced. It’s actually not that easy to release widget memory…

If you Create Widget → Add to Viewport, the viewport is now the parent container and the GC will not scoop it. For the Collect Garbage to kick in, you’d need to Remove From Parent & null Set all references, if any exist.

Hi Everynone, thanks for your comment. I’ll keep using the garbage container then since it’s the only way I found to clean up any non-referenced widgets.