Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngOnDestroy not firing when provide is an abstract class #14821

Closed
colinkahn opened this issue Mar 1, 2017 · 14 comments
Closed

ngOnDestroy not firing when provide is an abstract class #14821

colinkahn opened this issue Mar 1, 2017 · 14 comments
Labels
area: core Issues related to the framework runtime core: di P5 The team acknowledges the request but does not plan to address it, it remains open for discussion state: confirmed type: bug/fix
Milestone

Comments

@colinkahn
Copy link

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
When specifying a provider where provide is an abstract class and useClass is a concrete one, ngOnDestroy will never be called in the concrete class.

Expected behavior
ngOnDestroy should be called.

Minimal reproduction of the problem with instructions
https://plnkr.co/edit/eIs7pjvldhcFrMmaJ4IV?p=preview

  1. Open the console.
  2. Click the "Create Component" button one or many times
  3. After a 2 second delay the component will be destroyed, but no console output will be seen.

What is the motivation / use case for changing the behavior?
Providing abstract classes with concrete implementations that utilize ngOnDestroy to do cleanup.

Please tell us about your environment:

  • Angular version: 2.4.8
  • Browser: Chrome 56.0.2924.87
  • Language: TypeScript 2.0

  • Node (for AoT issues): node --version =

@colinkahn colinkahn changed the title ngOnDestroy not firing when provide is an abstract class ngOnDestroy not firing when provide is an abstract class Mar 1, 2017
DzmitryShylovich added a commit to DzmitryShylovich/angular that referenced this issue Mar 1, 2017
DzmitryShylovich added a commit to DzmitryShylovich/angular that referenced this issue Mar 1, 2017
DzmitryShylovich added a commit to DzmitryShylovich/angular that referenced this issue Mar 1, 2017
@IgorMinar IgorMinar added area: core Issues related to the framework runtime type: bug/fix labels Mar 13, 2017
@ngbot ngbot bot added this to the Backlog milestone Jan 23, 2018
@LaniMoo
Copy link

LaniMoo commented Mar 27, 2018

Is there a workaround for this?

@trotyl
Copy link
Contributor

trotyl commented Aug 4, 2018

Duplicate of #14818, has been fixed by #23755

@tapthoppe
Copy link

what status of this?

@andreyjamer
Copy link

The problem is still reproduced on v 6.1.0 where it was fixed.
If provide service in component with useClass, then onDestroy is not fired.
If provide service directly, then everything is ok.

@andreyjamer
Copy link

andreyjamer commented Nov 1, 2018

Prepared example on v 7.0.1 to show the problem - https://stackblitz.com/edit/angular-qxrald

Click the "toggle" button one or many times
Direct provided service will be created and destroyed.
Factory provided service and Use class provided service will be created and never destroyed.

It may cause memory leaks, i guess.

@trotyl
Copy link
Contributor

trotyl commented Nov 1, 2018

Confirmed, #23755 is only for NgModule providers, but didn't fix the Directive providers cases.

@andreyjamer
Copy link

Any update on this issue?
I guess all services provided in components are affected.
Not sure if it causes memory leaks, but it definitely could.

@Rush
Copy link

Rush commented Jan 20, 2020

Any update on this issue?

@distante
Copy link

distante commented Feb 6, 2020

Is this bug active for almost two years now or did I saw something wrong?

Edit: Yes I saw something wrong. It is almost 3 years.

@kara
Copy link
Contributor

kara commented May 27, 2020

This is a real View Engine bug. See updated Stackblitz with v9 here:
https://stackblitz.com/edit/angular-ivy-ir1nzk?file=src%2Fapp%2Fhello.component.ts

The useClass issue is fixed with Ivy, though:

https://stackblitz.com/edit/angular-ivy-bsnzpz?file=src/app/hello.component.ts

@distante
Copy link

@kara this also happens when the service is provided locally using a factory. And it is not fixed by ivi. Or that is another bug?

@kara
Copy link
Contributor

kara commented May 28, 2020

@distante I view them as separate issues because factories would be more complicated to support. That issue is tracked here

@jelbourn jelbourn added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Oct 1, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Oct 1, 2020
@jelbourn jelbourn added P5 The team acknowledges the request but does not plan to address it, it remains open for discussion and removed P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent severity3: broken labels Oct 1, 2020
@AndrewKushnir
Copy link
Contributor

Closing this ticket since it was marked as ViewEngine-specific and ViewEngine is deprecated. Please reopen if the problem still exists in the latest version of Angular (powered by Ivy).

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime core: di P5 The team acknowledges the request but does not plan to address it, it remains open for discussion state: confirmed type: bug/fix
Projects
None yet