# TextBlock inside RetainerBox causes "Leak Detected" message when containing UUserWidget is moved in the UMG Designer

**URL:** <https://forums.unrealengine.com/t/textblock-inside-retainerbox-causes-leak-detected-message-when-containing-uuserwidget-is-moved-in-the-umg-designer/482997>\
**Category:** UI\
**Tags:** memory-leak, unreal-engine, Widget, CPP, question\
**Created:** [May 6, 2021, 4:39pm UTC](https://forums.unrealengine.com/t/textblock-inside-retainerbox-causes-leak-detected-message-when-containing-uuserwidget-is-moved-in-the-umg-designer/482997 "2021-05-06T16:39:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RGARDEN1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RGARDEN1](https://forums.unrealengine.com/u/RGARDEN1)\
**Post date:** [May 6, 2021, 4:39pm UTC](https://forums.unrealengine.com/t/textblock-inside-retainerbox-causes-leak-detected-message-when-containing-uuserwidget-is-moved-in-the-umg-designer/482997/1 "2021-05-06T16:39:37Z")

</div>

I have a minimal project which declares a C++ UUserWidget class called USimpleBase, like this:

```
UCLASS()
class MY_API USimpleBase : public UUserWidget
{
	GENERATED_BODY()

	protected:
		virtual TSharedRef<SWidget> RebuildWidget() override;
};

```

It implements RebuildWidget() like this:

```
TSharedRef<SWidget> USimpleBase::RebuildWidget()
{
	auto UnderlyingWidget = Super::RebuildWidget();

	auto Canvas = Cast<UCanvasPanel>(GetRootWidget());

	auto RetainerBox = WidgetTree->ConstructWidget<URetainerBox>(URetainerBox::StaticClass());
	auto CanvasSlot = Cast<UCanvasPanelSlot>(Canvas->AddChild(RetainerBox));

	// Anchor the retainer box to stretch fill the canvas.
	// This way, when the user resizes us, it will resize the retainer box the same way. 
	CanvasSlot->SetAnchors(FAnchors(0.0f, 0.0f, 1.0f, 1.0f));
	CanvasSlot->SetAlignment(FVector2D(0.0f, 0.0f));
	CanvasSlot->SetOffsets(FMargin(0));

	// Add a text block inside the retainer box.
	auto TextBlock = WidgetTree->ConstructWidget<UTextBlock>(UTextBlock::StaticClass(), "TextBlock");
	RetainerBox->SetContent(TextBlock);
	TextBlock->SetText(FText::FromString(TEXT("Hello")));

	return UnderlyingWidget;
}

```

I create a new widget in the content browser called BP\_Simple, open it, and in the UMG Designer,  
reparent it to USimpleBase.

I create another widget called BP\_TestView, open it, and in the Designer,  
place an instance of BP\_Simple on the layout.

The widget shows up okay, but if I move it, an ensure() check fails in FWidgetBlueprintEditor::DestroyPreview  
on this line:

```
ensure(!PreviewSlateWidgetWeak.IsValid());

```

and this log message occurs:

```
LogBlueprint: Warning: [Compiler] Leak Detected! CanvasPanel_0 ( Canvas Panel ) still has living Slate widgets, it or the parent widget is keeping them in memory. Release all Slate resources in ReleaseSlateResources().

```

Placing a different widget (like an OverlayPanel) inside the RetainerBox is fine.  
Placing the TextBlock inside the Canvas is fine.  
It’s only when placing the TextBlock inside the RetainerBox that the problem occurs.  
The problem also happens if we have this widget hierarchy:

```
RetainerBox
	OverlayPanel
		TextBlock

```

Suggesting that if a TextBlock is anywhere a child of a RetainerBox, it’s a problem.

I’ve verified with dumps of the USimpleBase’s WidgetTree that it has exactly  
the widgets created and nothing else (Canvas, RetainerBox, TextBlock). It also  
looks okay in the Widget Reflector tool at runtime.

I’ve looked at the ReleaseSlateResources() implementations for UUserWidget, Canvas, RetainerBox, and TextBlock  
and they all seem okay. If I had to guess, TextBlock or the Slate prepass system is making some assumption about  
the TextBlock’s container?

---

<div class="post-metadata">

**Author:** ![Nonlin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nonlin](https://forums.unrealengine.com/u/Nonlin)\
**Post date:** [April 9, 2024, 10:54pm UTC](https://forums.unrealengine.com/t/textblock-inside-retainerbox-causes-leak-detected-message-when-containing-uuserwidget-is-moved-in-the-umg-designer/482997/2 "2024-04-09T22:54:01Z")

</div>

Did you ever resolve this? I can’t seem to figure out why my custom UUserWidget is leaky…
