Skip to content

Memory referenced by component state is not released when unmounted #15208

Closed
@syranide

Description

@syranide

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
https://jsfiddle.net/z5ejtay2/ (EDIT: Updated with a better fiddle.)

Use Chrome, open fiddle, click on the date-output a few times so that it refreshes. Each creates a new XTest-object. Use the developer-memory tab in Chrome and record a new Heap Snapshot (for fiddle.jshell.net). If you search for XTest in the snapshot you'll see 3 or so instances.

Uncomment the componentWillUnmount-line and retry the same again. There will only be a single XTest allocation as expected.

So it seems that references to dead component instances are being retained by React, not forever, but for longer than they should. In my own more realistically complicated app it's not as apparent that they are being released at all, it's just continually increasing and they are never being released.

PS. This is currently a significant (but workaround-able) problem for me, because I'm instancing a memory-heavy editor which is currently causing memory to continually increase.

What is the expected behavior?
Immediately release references so that memory can be reclaimed.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
16.8.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions