-
-
Notifications
You must be signed in to change notification settings - Fork 122
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
changeLocale resulting in upstream memory "leak" #280
Comments
Ya, I can imagine this causing an issue for both fastboot + test runs. Good catch! Just to make sure I'm following correctly. We essentially keep growing this object https://github.com/moment/moment/blob/497f918/src/lib/locale/locales.js#L13 because for each If that is the case, the leak still occurs for people who switch locals if they provide their own config. Given that, it would seem like we may need a way to delete entries from moments |
Basically, moment.js itself behaves "badly" if you continuously call their So, given that, the problem lies in ember-moment: we conflate For guaranteed consistency you must instead do: import moment from 'moment';
export default Service.extend({
moment: service(),
init() {
moment.locale('en-gb'); // There is no way to reach through and do this from the service's public API.
this.set('moment.locale', 'en-gb');
}
}); |
@nathanhammond can you think of any downsides to, if not lets just doit:
cc @jasonmit |
Any user who is relying on We currently have two sources of truth for
We elected for Option 2 in our codebase. |
I'm all for option 2 as well. Worth noting, we will lose the ability for the helpers to recompute on locale and timezone changes. |
This results in a memory "leak" inside of moment.js:
https://github.com/stefanpenner/ember-moment/blob/26d8a29/addon/services/moment.js#L45
The default empty object passed in changes the invocation signature here:
https://github.com/moment/moment/blob/497f918/src/lib/locale/locales.js#L119
As a consequence, each invocation to
updateLocale
creates a newLocale
which ends up with a reference to the previousLocale
inparentLocale
. If you do any configuration upon instantiation of an object (e.g. aService
) in a particularApplicationInstance
you end up with one leakedLocale
perApplicationInstance
. (In normal apps, no big deal, FastBoot apps, things aren't good.)Recommended Fix
There should be no default value of
{}
for thechangeLocale
function as the function that it proxies to has no default value. This modification inember-moment
effectively changes the upstream method signature.Workaround
A user of
ember-moment
can pass anull
orundefined
second argument toMomentService#changeLocale
.The text was updated successfully, but these errors were encountered: