Skip to content

Conversation

@Eddman
Copy link
Contributor

@Eddman Eddman commented Jun 16, 2017

Listeners are only registered inside of UniqueSelectionDispatcher. But there were never removed causing in my case a small memory leak when using MdButtonToggle.

In this fix UniqueSelectionDispatcher.listen returns a function that removes the listener once called.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 16, 2017
@jelbourn jelbourn self-requested a review June 16, 2017 17:37
@Eddman
Copy link
Contributor Author

Eddman commented Jun 19, 2017

Please merge ASAP: it is causing huge mem-leaks in my application so it makes the Chrome tab to crash in few minutes...

In combination with #5144 I'm almost unable to use the library. We are managing a big data set that is leaking because of these...

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Just a few comments

* Listen for future changes to item selection.
* @return Function used to unregister listener
**/
listen(listener: UniqueSelectionDispatcherListener): Function {
Copy link
Member

Choose a reason for hiding this comment

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

The return type is () => void

private _isSingleSelector: boolean = null;

/** Unregister function for _buttonToggleDispatcherListener **/
private _buttonToggleDispatcherListener: Function;
Copy link
Member

Choose a reason for hiding this comment

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

Call this _removeUniqueSelectionListener, type is () => void and initialize it to () => {}:

private _removeUniqueSelectionListener: () => void = () => {};

Then you don't have to check if it is defined in the ngOnDestroy

(same change for other components as well)

@devversion this is potentially a good case for a mixin in a follow-up PR

this.checked = false;
}
});
this._buttonToggleDispatcherListener = _buttonToggleDispatcher.listen(
Copy link
Member

Choose a reason for hiding this comment

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

Prefer line-breaking at the higher syntactic level, e.g.

this._removeUniqueSelectionListener =
    _buttonToggleDispatcher.listen((id: string, name: string) => {
      if (id != this.id && name == this.name) {
        this.checked = false;
      }
    });

return () => {
this._listeners = this._listeners.filter((registered: UniqueSelectionDispatcherListener) => {
return listener !== registered;
});
Copy link
Member

Choose a reason for hiding this comment

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

This also needs a unit test. It should set up a listener, then deregister and assert that listener isn't called again on notify

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. See unique-selection-dispatcher.spec.ts.

@Eddman
Copy link
Contributor Author

Eddman commented Jun 20, 2017

@jelbourn All comments are implemented.

@Eddman Eddman changed the title Fixed memory leaking in UniqueSelectionDispatcher fix(memory leak): memory leaking in UniqueSelectionDispatcher Jun 20, 2017
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Jun 20, 2017
@jelbourn jelbourn merged commit f9bbbe7 into angular:master Jun 22, 2017
@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 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants