AdamEssenmacher / MemoryToolkit.Maui

A developer toolkit for detecting, diagnosing, and mitigating memory leaks in .NET MAUI applications.
MIT License
258 stars 14 forks source link

Clear label formatted text on tear down #13

Open domneedham opened 5 months ago

domneedham commented 5 months ago

If a label uses spans in the formatted string, it doesn't seem to register it as children on the element.

<Label
    MaxLines="2"
    LineBreakMode="WordWrap"
    VerticalOptions="Center">

    <Label.FormattedText>
        <FormattedString>
            <Span Text="Text One" />

            <!--Add blank space between normal text and link text-->
            <Span Text=" " />

            <Span Text="Text Two" TextDecorations="Underline">
                <Span.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding CommandHere}" />
                </Span.GestureRecognizers>
            </Span>
        </FormattedString>
    </Label.FormattedText>
</Label>

Therefore, the spans are not getting cleared in TearDownImpl.

Adding the following seems to work.

if (vte is Label label)
{
    if (label.FormattedText != null)
    {
        TearDownImpl(label.FormattedText);
    }
}

Happy to discuss further if required.

AdamEssenmacher commented 5 months ago

Agreed. PR or I'll try to get to it when I can.