adopted-ember-addons / adopted-ember-addons/ember-cp-validations
Memory Leaks
- Langage dominant
- JavaScript
- Étoiles
- 439
- Forks
- 172
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
Hello :)
While investigating memory leak(s) in our tests, I came across a couple in this repo.
- `ResultCollection` is not getting cleaned up when another collection is created [here](https://github.com/offirgolan/ember-cp-validations/blob/f0f8a92fdc2d09721b7acc4afd61fdbfae33e030/addon/validations/factory.js#L405). Every time the validations run, the previous result collection is not collected. I suspect this may be an Ember core issue where object and array proxies don't get cleaned up ([related issue](https://github.com/emberjs/ember.js/issues/14802)).
- This [`Validations` variable](https://github.com/offirgolan/ember-cp-validations/blob/f0f8a92fdc2d09721b7acc4afd61fdbfae33e030/addon/validations/factory.js#L99) survives across app resets/destruction (which means it survives between tests) because it's used by [the `ValidationsMixin`](https://github.com/offirgolan/ember-cp-validations/blob/f0f8a92fdc2d09721b7acc4afd61fdbfae33e030/addon/validations/factory.js#L101) whose lifetime is the same as the containing module's lifetime The issue is that to create `Validations` we pass a reference of the [first instance that needs it](https://github.com/offirgolan/ember-cp-validations/blob/f0f8a92fdc2d09721b7acc4afd61fdbfae33e030/addon/validations/factory.js#L117). This causes the instance that triggered the creation of the `Validations` class to survive even after the application is destroyed. If that instance was created by the container, it has a reference to that container, which means the container doesn't get cleaned up, and since the container has a reference to the application and all singletons, the application and most of its instances don't get cleaned up. So at the end of every test, we'll have an extra application in memory. With enough tests we were quickly reaching Gigabytes of memory.
- We are also keeping a reference of the first instance that uses the validations mixin [in the validation rules object](https://github.com/offirgolan/ember-cp-validations/blob/f0f8a92fdc2d09721b7acc4afd61fdbfae33e030/addon/validations/factory.js#L712) whose lifetime is the module's lifetime and not the application's lifetime. This also keeps the model instance and its container and application alive. Cloning `v` [here](https://github.com/offirgolan/ember-cp-validations/blob/f0f8a92fdc2d09721b7acc4afd61fdbfae33e030/addon/validations/factory.js#L712) before assigning `model` to it may be enough.
I hope this is helpful, and thank you for this great addon!
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.