angular: [platform-server] SSR for Standalone Component: bootstrapApplication have memory leaks

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

platform-server

Is this a regression?

No

Description

ngModule version

I clone the Angular Universal repo version from angular:

  • checkout master then: pnpm install
  • pnpm dev:ssr to serve
  • nodemon --inspect=localhost:9236 dist/server/main.js to inspect

Then I start it and make a heap snapshot. it’s fine. Open dev tools for Node.js to inspect, Go to memory tab, search module keyword image

first-time load home page: image load home page at second time: image

load home page at 20th times: image

everything is fine and no leak. NgModule only have 2 instance

Standalone version

I upgrade the universal version of the standalone component, I’m going to make this on the universal repo, but first, it has a memory leak.

  • checkout master then: pnpm install
  • pnpm dev:ssr to serve
  • nodemon --inspect=localhost:9236 dist/server/main.js to inspect

go home page and f5 for 6 times: image

go home page and f5 for more 5 times: image

we get too many modules that are not clear and the heap memory goes “To infinity and beyond”. The ApplicationModule goes to x6 on 6 load pages, and x11 if you have 11 load pages.

Please provide a link to a minimal reproduction of the bug

https://github.com/hiepxanh/universal-test

Please provide the exception or error you saw

No response

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

Angular CLI: 14.0.2
Node: 16.13.1
Package Manager: pnpm 7.1.5
OS: win32 x64

Angular: 14.0.3
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1400.2
@angular-devkit/build-angular   14.0.2
@angular-devkit/core            14.0.2
@angular-devkit/schematics      14.0.2
@angular/cli                    14.0.2
@nguniversal/builders           14.0.1
@nguniversal/common             14.0.1
@nguniversal/express-engine     14.0.1
@schematics/angular             14.0.2
rxjs                            7.5.5
typescript                      4.7.4

Anything else?

I’m running the standalone SSR version in my production version. Current work around is restart the server 😄

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (14 by maintainers)

Commits related to this issue

Most upvoted comments

@hiepxanh just wanted to let you know that we’ve released Angular v14.0.4, which contains the memory leak fix. Please try updating to the latest version and let us know if the problem is resolved. Thank you.

@AndrewKushnir thank you, sir. There is no sign of the memory leak anymore. image

After routing about 100 routes, the memory is still stable. everything is fine. I think I can use it now ❤️

@AndrewKushnir I already test it, and I see the result is very good. Thank you for your effor image

in my production app, it goes really bad, it takes 1 day only to eat my 1 GB ram.

Side note: this API is still experimental and should not be used in production.