Download

Should I call UUserWidget::BeginDestroy to explictyl destroy the widget and release the memory?

Should I call UUserWidget::BeginDestroy to explictyl destroy the widget and release the memory or other method could help to cleanly destroy the Widget and release its memory?

It crashes when UUserWidget::BeginDestroy executes.

Just remove it from viewport and let the garbage collection deal with the rest. You can of course also set your pointer to null if you really want to but that’s unnecessary in my opinion.

It will take some time to let the garbage collector to recycle its resources and memory after UUserWidget::RemoveFromParent being executed.

Well, sure, but why do you need to be so quick about it? It won’t really have an impact on your game’s performance.

Never destroy widgets manually.

Your best bet, is caching in advance all possible widgets, and when you no longer need them, call remove from parten (from lowest child to highest parent).

When you don’t need widget at particular time use SetIsEnabled(false), and SetVisibility(ESlateVisibility::Collapsed).

From what I read manually destroying widgets is not intended workflow, and it frankly simply doesn’t work.