Skip to content

Blazor memory leak due to nested bind-Value #28518

@Mr-Technician

Description

@Mr-Technician

Describe the bug

Nesting components that make use of @bind-Value will result in a memory leak. This occurs on both .NET Core 3.1, .NET 5.0, in both Blazor server and Blazor WASM, and on IIS Express and IIS.

To Reproduce

Create a new component BindComponent and add this code to it:

<input type="text" class="form-control" @bind-value="Value" />

@code {
    [Parameter]
    public string Value
    {
        get => hidden;
        set
        {
            hidden = value;
            ValueChanged.InvokeAsync(value);
        }
    }
    [Parameter]
    public EventCallback<string> ValueChanged { get; set; }
    private string hidden;
}

In any other component, reference the component:

<BindComponent @bind-Value="bound"></BindComponent>

@code {
    string bound { get; set; }
} 

Run the application and type something in the text box, then tab out. Check Visual Studio dev tools and you will see a memory leak.

I know there are ways around this issue but I doubt this should cause Blazor to leak memory.

Exceptions (if any)

Not applicable.

Further technical details

  • ASP.NET Core version: .NET Core 3.1, .NET 5.0 (Blazor Server and Blazor WASM)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions