Skip to content

Incorrect documentation for fixing memory leaks #1082

@jadengeller-asana

Description

@jadengeller-asana

The "isMounted is an Antipattern" documentation article suggest avoiding memory leaks with makeCancelable, but this doesn't actually solve the issue since the callback is still referenced. The garbage collector does not understand that setting hasCanceled_ means that resolve will never be called, so it cannot release resolve or the references contained within. Even if it could, reject might also reference this, so memory leaks could still exist. Instead, makeCancelable should store the resolve and reject callbacks itself, and it should null them out on cancelation.

Another user pointed this issue out in facebook/react#5465 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions