Skip to content

Blazor WASM leaves detached nodes #61190

Open
@Dargazo

Description

@Dargazo

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

There seems to be a memory leak when creating/destroying elements inside an if statement on user input.

Expected Behavior

No detached nodes when elements are dynamically destroyed/created. When

Steps To Reproduce

I've created a repro solution here: https://github.com/Dargazo/BlazorDetachedNodeRepro/tree/master

  • Start the app in (tested in Edge/Chrome)
  • Open Developer tools (F12)
    -- Open the Memory tab
    -- Select the 'Detached elements' option
  • Press the 'Take snapshot' button
  • Observe: Some detached nodes, this is our baseline
  • On the app page, increment the CurrentNumber using the rendered 'InputNumber' element
  • Observe: two new InputElements are now rendered
  • Now back in the developer tools, press the 'Take snapshot' button again
  • Observe: a new <input .... _bl_2> element is now also detached.
  • Back on the app, decrement the CurrentNumber using the rendered 'InputNumber' element
  • Take another snapshot and
  • Observe: another two <input ... > elements are added.

Note: Pressing the 'Click me Up' / 'Click me Down' seem to properly clear the input elements and not leave them detached.
Note: clicking inside one of the InputNumber elements, and then clicking the 'Click me Up'/'Click me Down' buttons also leaves detached nodes

Exceptions (if any)

No response

.NET Version

9.0.201

Anything else?

This is a minimal repro. We came across this issue in our application, where we (re)create UI based on selected elements and use switch statements to decide what components to render. This rose up to sometimes hundreds of detached nodes when switching between elements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions