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
APP_INITIALIZER with HttpClient provoke memory leak in SSR projects #55396
Comments
By any chance could you run the same tests without the fetch implementation ? (remove |
Hey @JeanMeche, I removed
|
I gave it a look and can provide 2 minimal repro :
This is linked to the It looks like this is a dev-mode issue. When optimisation are enabled, I can't reproduce the leak. @dancornilov Care to retry with |
I am not sure that I fully understand you, just to confirm: I retried my tests with |
I was mislead initially because the webpack builder didn't have the optimization enabled. |
I understand that this issue is most dev-only mode, but this is mistake or trade-of? |
Its likely due to some debug/devtools related code. Those are only shipped on devbuilds. This why the Angular devtools only works on devbuilds for example. |
@alxhub, suspects that the Injector Profiler is causing the leak.
|
Although keys are not strongly referenced in a `WeakMap`, values are, potentially leading to data retention issues and improper garbage collection. By utilizing `WeakRef`, this problem can be mitigated effectively. Weak references allow the garbage collector to collect an object even if it is only weakly referenced. This can prevent memory leaks in the injector debugger profiler. Closes angular#55396
Although keys are not strongly referenced in a `WeakMap`, values are, potentially leading to data retention issues and improper garbage collection. By utilizing `WeakRef`, this problem can be mitigated effectively. Weak references allow the garbage collector to collect an object even if it is only weakly referenced. This can prevent memory leaks in the injector debugger profiler. Closes angular#55396
Closed via #55530 |
Which @angular/* package(s) are the source of the bug?
common, core
Is this a regression?
Yes
Description
In my Angular 17 SSR project, I encountered a problem with memory consumption. Typically, this issue can arise due to unsubscription or intervals, but not this time.
After several weeks of debugging and refactoring everything that came to mind and could potentially cause this problem, I sought help from other friends, colleagues, and developers. Ultimately, after a full day of debugging, the bug was identified: the memory leak was caused by the
HttpClient
used inAPP_INITIALIZER
.Right now, I've found a workaround to avoid this issue by creating a WrapperComponent which wraps all my routes, and I use a resolver to prevent HTTP requests in APP_INITIALIZER.
Please provide a link to a minimal reproduction of the bug
https://github.com/dancornilov/initializer-memory-leak
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run
ng version
)Anything else?
Please take a look in provided repository for minimal reproduction of the bug, in README is describe the full flow how to reproduce this issue.
The text was updated successfully, but these errors were encountered: