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

Conversation

steve8708
Copy link
Contributor

@steve8708 steve8708 commented Sep 27, 2016

  • Please check if the PR fulfills these requirements
  • The commit message follows our guidelines: https://github.com/angular/universal/blob/master/CONTRIBUTING.md#commit-message-format
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • What modules are related to this pull-request
  • express-engine
  • grunt-prerender
  • gulp-prerender
  • hapi-engine
  • universal-next
  • universal
  • webpack-prerender
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    Fixes a memory leak
  • What is the current behavior? (You can also link to an open issue here)
    If you run servers in production, NgModules are generated per request and cached indefinitely, leading to a serious memory leak that will eventually floor your servers and you'll have to restart them constantly (up to every 15 minutes!)
  • What is the new behavior (if this is a feature change)?
    Use WeakMap instead of Map to ensure if all references are lost to a cache key the value is garbage collected
  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
    No
  • Other information:

@PatrickJS PatrickJS merged commit a135196 into angular:master Sep 27, 2016
@PatrickJS
Copy link
Contributor

LGTM, thanks!

@steve8708
Copy link
Contributor Author

Rad, thank you!

// TODO(gdi2290): hide cache in (ngPreboot|UniversalPreboot)
let prebootConfig = null;
let key = (typeof preboot === 'object') && JSON.stringify(preboot) || null;
let key = (typeof preboot === 'object') && preboot || null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the goal of this cache was reusing the same prebootEl but I guess the biggest problem was probably not detaching it from the dom after destroying the app. If we move preboot to createEngine() which is the plan then this is fine since we're maintaining the same reference to the preboot config. During each req/res we're creating a new preboot config which was why I wanted to ensure if the configs are the same that we reuse the preboot element

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I was curious if that was why this was being stringified! Makes sense, and I frankly would've left it but WeakMaps don't support non-object keys so to get the memory releasing map it has to be the original object

Until moving to createEngine(), could also consider using an LRU or LFU cache in that case if you want to have serialized keys in this cache without risks of memory leaks. happy to send a followup PR if there is any other way you want this implemented here 👍

@aecz aecz mentioned this pull request Dec 21, 2016
2 tasks
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants