Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Destroying an angular app #7578

Open
Open
@shahata

Description

@shahata

I've been playing around this weekend with a project that I've been meaning to open source for a while now: https://github.com/shahata/angular-widget

In a nutshell, it let's you create many "widgets" in a single page, each widget is lazy loaded and has it's own injector and all of them live together nicely in one page. Demo at: http://shahata.github.io/angular-widget/#

When you click "add..." a widget is added, and when you click "del" it is destroyed. I'm no performance expert, but if I look in developer tools I see that destroyed widgets are cleaned up nicely.

The problem is, that if I add a "bad" widget it does not get cleaned up so nicely. What's bad about this widget? Well, it uses $cookies. $cookies polls the browser's cookie storage every 100ms to check if cookies were updated. It start to poll when it is created and stop... well, never. So if I add many "bad" widgets, I have many polling timeouts of $cookies and even if I remove all the widgets polling continues, and I guess also prevents GC.

I would like to try and add a mechanism for destroying angular apps in order to deal with this kind of issues. If this is something desirable for angular, I can take this PR. The design I have in mind is that users will be able to call injector.$destroy() and the injector will then call $destroy on every injectable that has a $destroy method which in turn will cancel any pending actions like timeouts, intervals, http requests, etc.

$rootScope obviously already has a $destroy method, though it is a bit partial - see #7564

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions