Deliver web apps with confidence 🚀
Find a file
arturovt 1bbf75017c fix(common): cleanup updateLatestValue if view is destroyed before promise resolves (#58041)
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
2025-05-01 14:53:13 -07:00
.devcontainer ci: remove circleci as we no longer rely on it (#58615) 2024-11-12 18:39:25 +00:00
.github build: update cross-repo angular dependencies (#61069) 2025-04-30 15:12:30 -07:00
.husky build: simplify husky setup (#54315) 2024-02-07 16:34:13 +00:00
.ng-dev docs: address comments (#58786) 2025-03-04 19:35:54 +00:00
.vscode build: add ignore revs file for git blame (#60117) 2025-02-26 16:19:25 -05:00
.yarn build: update yarn to 1.22.22 (#58448) 2024-10-31 19:06:16 +01:00
adev docs: Add docs for CoC plugin with neovim (#61005) 2025-05-01 08:41:46 -07:00
contributing-docs docs: mention that log format makes it analyzable for changelog generation. (#58786) 2025-03-04 19:35:54 +00:00
devtools feat(devtools): defer blocks support (#60629) 2025-04-29 22:07:47 -07:00
goldens refactor(service-worker): drop error messages in production (#59702) 2025-04-30 12:41:36 -07:00
integration fix(core): properly handle app stabilization with defer blocks (#61040) 2025-04-30 12:37:02 -07:00
modules feat(core): Move zoneless change detection to dev preview (#60748) 2025-04-23 11:47:56 +02:00
packages fix(common): cleanup updateLatestValue if view is destroyed before promise resolves (#58041) 2025-05-01 14:53:13 -07:00
scripts ci: remove circleci as we no longer rely on it (#58615) 2024-11-12 18:39:25 +00:00
third_party build: create NodeJS ESM loader for supporting Bazel setup (#48521) 2022-12-19 19:50:40 +00:00
tools build: Run browsers tests without platform-browser-dynamic (#60937) (#61060) 2025-04-30 08:21:02 -07:00
.bazelignore test: add integration test for platform-server with zoneless (#61040) 2025-04-30 12:37:01 -07:00
.bazelrc ci: update bazel RBE setup on CI and use trusted build configuration for upstream CI runs (#60589) 2025-03-27 18:16:09 +00:00
.bazelversion build: update to bazel v5 for new runfiles API used in dev-infra (#45407) 2022-03-21 16:55:36 -07:00
.clang-format feat(tooling): Add a .clang-format for automated JavaScript formatting. 2015-04-02 08:44:34 -07:00
.editorconfig build: use https link to editorconfig.org in .editorconfig (#27664) 2018-12-18 09:30:09 -08:00
.git-blame-ignore-revs build: exclude relative imports commits via .git-blame-ignore-revs (#60680) 2025-04-01 20:18:36 +00:00
.gitattributes build: cleanup .gitattributes file and remove outdated CRLF attribute (#46513) 2022-06-28 13:38:27 -07:00
.gitignore build: correct ignore nested node_modules (#58821) 2024-11-22 14:56:23 +00:00
.gitmessage docs: move commit message guidelies to a separate file (#58786) 2025-03-04 19:35:54 +00:00
.mailmap build: add a Git .mailmap with my new name (#19550) 2017-10-09 14:35:30 -07:00
.npmrc build: rely on engines to prevent using npm for dependency install (#41477) 2021-04-07 12:05:01 -07:00
.nvmrc build: update all non-major dependencies (#60969) 2025-04-23 10:58:16 +02:00
.prettierrc build: Update prettierrc to always use trailing commas (#58266) 2024-11-04 18:14:05 +01:00
.pullapprove.yml ci: add hawkgs to pullapprove (#60536) 2025-03-26 20:39:31 -07:00
.yarnrc build: update yarn to 1.22.22 (#58448) 2024-10-31 19:06:16 +01:00
browser-providers.conf.d.ts build: share Saucelabs browsers between karma test targets using background Saucelabs daemon and custom karma launcher (#49200) 2023-05-15 09:21:46 -07:00
browser-providers.conf.js refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
BUILD.bazel build: update yarn to 1.22.22 (#58448) 2024-10-31 19:06:16 +01:00
CHANGELOG.md docs: release notes for the v20.0.0-next.9 release 2025-04-30 10:40:58 -07:00
CHANGELOG_ARCHIVE.md docs: fix typos 2023-06-22 12:56:49 +02:00
CODE_OF_CONDUCT.md build: update CODE_OF_CONDUCT.md to match the content of angular/.github 2023-03-13 21:07:51 +00:00
CONTRIBUTING.md docs: fix commit message guideline link (#60296) 2025-03-11 11:08:23 -07:00
gulpfile.js refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
karma-js.conf.js ci: remove circleci as we no longer rely on it (#58615) 2024-11-12 18:39:25 +00:00
LICENSE docs: update copyright year (#59359) 2025-01-06 19:58:30 +00:00
package.json build: update cross-repo angular dependencies to v20.0.0-next.10 (#61084) 2025-05-01 10:31:46 -07:00
packages.bzl refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
README.md docs: remove gitter reference (#60970) 2025-04-23 17:25:15 +02:00
renovate.json build: update development Node.js version to 22.14.0 and auto-update (#60545) 2025-03-26 20:42:16 -07:00
SECURITY.md docs: update security guide link to adev (#56469) 2024-06-17 08:54:08 -07:00
tsconfig-tslint.json docs(docs-infra): enable tslint (#58961) 2024-12-05 16:03:35 -08:00
tslint.json refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
WORKSPACE build: update io_bazel_rules_sass digest to cbe5261 (#60882) 2025-04-16 12:43:45 -04:00
yarn.bzl build: update yarn to 1.22.22 (#58448) 2024-10-31 19:06:16 +01:00
yarn.lock build: update cross-repo angular dependencies to v20.0.0-next.10 (#61084) 2025-05-01 10:31:46 -07:00

Angular - The modern web developer's platform

angular-logo
Angular is a development platform for building mobile and desktop web applications
using TypeScript/JavaScript and other languages.

angular.dev

Contributing Guidelines · Submit an Issue · Blog

Angular on npm   Discord conversation


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

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

Get started in 5 minutes.

Ecosystem

angular ecosystem logos

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.

Love Angular badge

Love Angular? Give our repo a star ⬆️.