According to the promise specification, promises are not cancellable by default. Once a promise is created, it will either resolve or reject, and it doesn't provide a built-in mechanism to cancel it. There may be situations where a promise is provided, and it either resolves after the pipe has been destroyed or never resolves at all. If the promise never resolves — potentially due to factors beyond our control, such as third-party libraries — this can lead to a memory leak. When we use `async.then(updateLatestValue)`, the engine captures a reference to the `updateLatestValue` function. This allows the promise to invoke that function when it resolves. In this case, the promise directly captures a reference to the `updateLatestValue` function. If the promise resolves later, it retains a reference to the original `updateLatestValue`, meaning that even if the context where `updateLatestValue` was defined has been destroyed, the function reference remains in memory. This can lead to memory leaks if `updateLatestValue` is no longer needed or if it holds onto resources that should be released. When we do `async.then(v => ...)` the promise captures a reference to the lambda function (the arrow function). When we assign `updateLatestValue = null` within the context of an `unsubscribe` function, we're changing the reference of `updateLatestValue` in the current scope to `null`. The lambda will no longer have access to it after the assignment, effectively preventing any further calls to the original function and allowing it to be garbage collected. If Chrome is built with additional flags and run with `--allow-natives-syntax --track-retaining-path`, we could use `%DebugTrackRetainingPath` to see the distance from the root for `updateLatestValue` if it's passed directly to async.then, e.g.: ```js %DebugTrackRetainingPath(updateLatestValue); // Distance from root 4: 0x123456789abc <JSPromise (sfi = 0x1fbb02e2d7f1)> ``` PR Close #58041 |
||
|---|---|---|
| .devcontainer | ||
| .github | ||
| .husky | ||
| .ng-dev | ||
| .vscode | ||
| .yarn | ||
| adev | ||
| contributing-docs | ||
| devtools | ||
| goldens | ||
| integration | ||
| modules | ||
| packages | ||
| scripts | ||
| third_party | ||
| tools | ||
| .bazelignore | ||
| .bazelrc | ||
| .bazelversion | ||
| .clang-format | ||
| .editorconfig | ||
| .git-blame-ignore-revs | ||
| .gitattributes | ||
| .gitignore | ||
| .gitmessage | ||
| .mailmap | ||
| .npmrc | ||
| .nvmrc | ||
| .prettierrc | ||
| .pullapprove.yml | ||
| .yarnrc | ||
| browser-providers.conf.d.ts | ||
| browser-providers.conf.js | ||
| BUILD.bazel | ||
| CHANGELOG.md | ||
| CHANGELOG_ARCHIVE.md | ||
| CODE_OF_CONDUCT.md | ||
| CONTRIBUTING.md | ||
| gulpfile.js | ||
| karma-js.conf.js | ||
| LICENSE | ||
| package.json | ||
| packages.bzl | ||
| README.md | ||
| renovate.json | ||
| SECURITY.md | ||
| tsconfig-tslint.json | ||
| tslint.json | ||
| WORKSPACE | ||
| yarn.bzl | ||
| yarn.lock | ||
Angular - The modern web developer's platform
Angular is a development platform for building mobile and desktop web applications
using TypeScript/JavaScript and other languages.
Contributing Guidelines
·
Submit an Issue
·
Blog
Documentation
Get started with Angular, learn the fundamentals and explore advanced topics on our documentation website.
Advanced
Local Development
To contribute to the Angular Docs, check out the Angular.dev README
Development Setup
Prerequisites
- Install Node.js which includes Node Package Manager
Setting Up a Project
Install the Angular CLI globally:
npm install -g @angular/cli
Create workspace:
ng new [PROJECT NAME]
Run the application:
cd [PROJECT NAME]
ng serve
Angular is cross-platform, fast, scalable, has incredible tooling, and is loved by millions.
Quickstart
Ecosystem
Changelog
Learn about the latest improvements.
Upgrading
Check out our upgrade guide to find out the best way to upgrade your project.
Contributing
Contributing Guidelines
Read through our contributing guidelines to learn about our submission process, coding rules, and more.
Want to Help?
Want to report a bug, contribute some code, or improve the documentation? Excellent! Read up on our guidelines for contributing and then check out one of our issues labeled as help wanted or good first issue.
Code of Conduct
Help us keep Angular open and inclusive. Please read and follow our Code of Conduct.
Community
Join the conversation and help the community.
- X (formerly Twitter)
- Bluesky
- Discord
- YouTube
- StackOverflow
- Find a Local Meetup
Love Angular? Give our repo a star ⭐ ⬆️.