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

fix($mdInteraction): clean up events on $rootScope destroy #11641

Merged
merged 1 commit into from
Mar 14, 2019

Conversation

codymikol
Copy link
Contributor

this prevents unit tests from leaking memory

Fixes: #11493

PR Checklist

Please check that your PR fulfills the following requirements:

  • The commit message follows our guidelines
  • Tests for the changes have been added or this is not a bug fix / enhancement
  • Docs have been added, updated, or were not required

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Enhancement
[ ] Documentation content changes
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

Currently the $mdInteraction service registers when invoked. This causes a memory leak in unit tests because nothing is in place to clean up the events.

Issue Number: #11493

What is the new behavior?

Now on the $destroy event of rootScope the events registered will be unregistered.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@googlebot googlebot added the cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ label Feb 19, 2019
@codymikol codymikol force-pushed the thin-interaction-fix branch from 41a35d0 to 7cb7b0e Compare February 19, 2019 02:31
@codymikol
Copy link
Contributor Author

I have another version that squishes the init and deregister methods into one that is passed 'on' or 'off', but thought this might be overly clever and less easily understood. It does have the have the benefit of having one place where events are manipulated so you don't have to worry about keeping both the init and deregister methods in sync. Let me know if that is preferred. 🐔

@Splaktar Splaktar self-assigned this Feb 26, 2019
@Splaktar Splaktar added P1: urgent Urgent issues that should be addressed in the next minor or patch release. severity: memory leak Issues where a memory leak is triggered. labels Feb 26, 2019
@Splaktar Splaktar added this to the 1.1.14 milestone Feb 26, 2019
Copy link
Contributor

@Splaktar Splaktar left a comment

Choose a reason for hiding this comment

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

This is great! Thank you!

Is there any way to verify this fix in a unit test? Maybe destroy the the rootScope and then check if the handlers are still there?

@Splaktar Splaktar added in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs needs: unit tests This PR needs unit tests to cover the changes being proposed labels Feb 26, 2019
@Splaktar
Copy link
Contributor

In the commit message, can you please change Fixes: #11493 to Fixes #11493?

this prevents unit tests from leaking memory

Fixes angular#11493
@codymikol codymikol force-pushed the thin-interaction-fix branch from 7cb7b0e to c5e2616 Compare February 28, 2019 02:55
@codymikol
Copy link
Contributor Author

In the commit message, can you please change Fixes: #11493 to Fixes #11493?

Changed 🐔

This is great! Thank you!

Is there any way to verify this fix in a unit test? Maybe destroy the the rootScope and then check if the handlers are still there?

I added unit tests that see if the lastInteractionType is modified after an event is fired. 🐔

Copy link
Contributor

@Splaktar Splaktar left a comment

Choose a reason for hiding this comment

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

LGTM

@Splaktar Splaktar added pr: merge ready This PR is ready for a caretaker to review pr: lgtm This PR has been approved by the reviewer and removed in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs needs: unit tests This PR needs unit tests to cover the changes being proposed labels Mar 13, 2019
@mmalerba mmalerba merged commit e9e9ece into angular:master Mar 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ P1: urgent Urgent issues that should be addressed in the next minor or patch release. pr: lgtm This PR has been approved by the reviewer pr: merge ready This PR is ready for a caretaker to review severity: memory leak Issues where a memory leak is triggered.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dialog: memory leak when injecting $mdDialog
4 participants