Skip to content

toSignal: remove cleanup callback from DestroyRef when Observable terminates #61511

@ajafff

Description

@ajafff

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

toSignal without manualCleanup: true adds a callback to DestroyRef to end the subscription when the injector is destroyed.

If the Observable terminates (error or complete) before the injector is destroyed, the callback is not removed from DestroyRef, leading to a memory leak.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)

19.2.11 (also present in master)

Anything else?

In my application I have a long-lived component that repeatedly uses toSignal based on external input. Those Observables typically end before the component is destroyed. But I want the last remaining subscriptions to be cancelled automatically when the component is destroyed.

As a workaround I could use manualCleanup: true with takeUntilDestroyed() .

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions